How do I define a data adapter?
The data adapter stores your command (query) and connection and using these connect to the database when asked, fetch the result of query and store it in the local dataset.
The DataAdapter class (SqlDataAdapter, OracleDataAdapter, OleDbDataAdapter, OdbcDataAdapter) may be instantiated in three ways:
- by supplying the command string (SQL Select command) and connection string
- by supplying the command string (SQL Select command) and a connection object
- by supplying the command object (SqlCommand, OracleCommand, OleDbCommand, OdbcCommand)
For example, with SQL Server, the data adapter is created as
C# Version
// for Sql Server
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn);
VB.Net Version
Dim da As New SqlDataAdapter(commandString, conn)
Here we have created a new instance of data adapter and supplied it command string and connection object in the constructor call.
For Access, the data adapter is created like
C# Version
// for MS Access
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
VB.Net Version
Dim da As New OleDbDataAdapter(commandString, connectionString)
Here we have created a new instance of data adapter and supplied it command string and connection string in the constructor call.
Back