intern_adodotnet_introduction.md - brainchildservices/curriculum GitHub Wiki

  • What is ADO.NET?

    • ADO stands for Microsoft ActiveX Data Objects.
    • ADO.NET is one of Microsoft’s Data Access technology.
    • It is a part of the .Net Framework which is used to establish a connection between the .NET Application and data sources.
    • The Data sources can be SQL Server, Oracle, MySQL, and XML, etc.
    • ADO.NET consists of a set of classes that can be used to connect, retrieve, insert and delete data from data sources.
    • ADO.NET mainly uses System.Data.dll and System.Xml.dll.
  • Components of ADO.NET

    • Components are designed for data manipulation and fast access to data.
    • Connection, Command, DataReader, DataAdapter, DataSet, and DataView are the components of ADO.NET that are used to perform database operations.
    • ADO.NET has two main components that are used for accessing and manipulating data. They are as follows:
      • Data provider and
      • DataSet.
  • What is .NET Data Providers?

    • The Database can not directly execute our C# code, it only understands SQL.
    • So, if a .NET application needs to retrieve data or to do some insert, update, and delete operations from or to a database, then the .NET application needs to
      • Connect to the Database
      • Prepare an SQL Command
      • Execute the Command
      • Retrieve the results and display them in the application
    • And this is possible with the help of .NET Data Providers.
  • ADO.NET code to connect to SQL Server Database

    • The following image shows the sample ADO.NET code which is connecting to SQL Server Database and retrieves data.

    • If you notice in the below image, here, we are using some classes such as SQLConnection, SQLCommand, and SQLDataReader.

    • These classes are called Provider classes and these classes are responsible for interacting with the database.

    • If you further notice all the classes are prefixed with the word SQL, it means these classes are going to interact with only the SQL Server database. image

    • All these classes are present in System.Data.SqlClient namespace.

    • We can also say that the .NET data provider for the SQL Server database is System.Data.SqlClient.

  • Note: The point that you need to remember is depending on the provider, the ADO.NET objects (Connection, Command, DataReader, and DataAdapter) have a different prefix as shown below.

    • Connection – SQLConnection
    • Command – SQLCommand
    • DataReader – SQLDataReader
    • DataAdapter – SQLDataAdapter
  • DataSet:

    • The DataSet object is not specific to provider-specific.
    • Once you connect to a database, execute the command, and retrieve data into the .NET application.
    • The data can then be stored in a DataSet and work independently of the database.
    • So, it is used to access data independently from any data source.
    • The DataSet contains a collection of one or more DataTable objects.
  • In our introduction part, we discussed that Connection, Command, DataAdapter, and DataReader objects are providers specific where the DataSet is provider independent. That means if you are going to work with SQL Server database, then you need to use SQL-specific provider objects such as SQLConnection, SqlCommand, SqlDataAdapter, and SqlDataReader objects which belong to the System.Data.SqlClient namespace.

  • REF Link: