Skip to main content

How To Create The Data Adapter Object Using ADO.NET by #RathrolaPremKumar

By reading this article, you will learn key points in ADO.NET, as given below.
  • What is Data Adapter?
  • Primary Data Adapters for the databases.
  • Data Adapter properties.
  • Methods used by Data Adapter.
  • How to create Data Adapter with an example?
Let’s start our demo with a Data Adapter introduction.
Actually, we use Data Adapter object to establish the connection to the data source and manage the movement of date to and from the database.
What is Data Adapter?
A data adapter aobject serves as a bridge between a data set object and Data Source such as a database to retrieve and save the data.
Data adapter contains a set of database commands and a database connection, which we use to fill a dataset object and update the Data Source.
Primary data adapters for databases?
.NET makes two primary data adapters available for use with the databases. Other data adapters can also be integrated with Visual Studio .NET.
Primary Data Adapters are mentioned below.
  • OleDbData Adapter, which is suitable for use with certain OLE DB providers.
  • SQLDataAdapaters, which is specific to a Microsoft SQL server. This is faster than the OleDBDataAdapter. because it works directly with SQL servers and does not go through an OLE Db Layer.
Data adapter properties
We use data adapter objects to act on records from a Data Source. We can also specify, which action we want to perform by using one of following four data adapter properties, which executes a SQL statement.
The properties are given below.
  • Select command retrieves rows from Data Source
  • Insert command writes inserted rows from data set into Data Source
  • Update command writes modified rows from data set into Data Source.
  • Delete command deletes rows from Data Source.
Methods used by a data adapter
Actually, we use data adapters to fill or to make changes in a data set table to a data store. These methods comprises of following.
  • FillUse this method of a SQL data adapter to add or refresh row from a Data Source and place them in a Data Set table. The fill method uses Select statement, which is specified in the Select command property
  • UpdateUse this method of data adapter object to transmit the changes to a dataset table to the corresponding Data Source. This method calls the corresponding insert, delete or update command for each specified row in a data table in a data set.
  • CloseUse this method for the connection to a database.
  • Creating Data Adapter with Example
    The examples given below use a SQLDataAdapter object to define a query in the database.
  1. using System;  
  2. using System.Data;  
  3. using System.Data.SqlClient;  
  4. namespace DataAdapter {  
  5.     class Program {  
  6.         static void Main(string[] args) {  
  7.             string connectionString = @ "data source=localhost;initial catalog=northwind;integrated security = SSPI";  
  8.             string commandString = @ "SELECT * from customers";  
  9.             SqlDataAdapter da = new SqlDataAdapter(commandString, connectionString);  
  10.             DataSet ds = new DataSet();  
  11.             DataAdapter.Fill(ds);  
  12.             DataTable dt = ds.Tables[0];  
  13.             int rows = dt.Rows.Count;  
  14.         }  
  15.     }  
  16. }  
Hence, this is the way of how can we create Data Adapter object, using ADO.NET. Thanks for reading this article. Sharing is caring.


Popular posts from this blog

ERROR: Cannot resolve the collation conflict between SQL_Latin1_General_CP1_CI_AS and Latin1_General_CI_AS_KS_WS in the equal to operation

ERROR: Cannot resolve the collation conflict between SQL_Latin1_General_CP1_CI_AS and Latin1_General_CI_AS_KS_WS in the equal to operation
dont get panic if u get the following error while in your joinings, there is a simple way to solve this.
it is because of collation settings on two columns we are doing joinings. it is because of collation settings on two columns we are doing joinings
First step is to figure out what are two colaltion that cause for conflicts. Let us assume that collation has not been set at the column level and instead at db level, then we have to execute two simple statements as below.

Statements: Select DATABASEPROPERTYYEX('DB1',N'Collation') Select DATABASEPROPERTYYEX('DB2',N'Collation')
One more thing, make a note that if you are on sharepoint you will get error as below
Latin_General_CI_AS_KS_WS. if you are on most any other database and use the dafault settings you may get this SQL_Latin_General_CP1_CI_AS.
Now we have to do some…

'#Resolve' To export a list, you must have a Microsoft SharePoint Foundation-compatible application.

Searching this error message easily finds the root of the problem. There is a problem with the Office 64 bit version. It doesn’t work with SharePoint. These solutions generally tell you to uninstall your 64 bit office and install a 32 bit version. Happily there is a much easier solution.
Despite the error message the export actually works! Notice the yellow bar at the bottom of your browser. Simply save the .iqy file normally and open it with Excel. It’s that simple. The error message is certainly a nuisance but does not actually stop the export.
Thanks for ready my blog :)