System.Data.Common Namespace DbDataAdapter Class
Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the DataSet.
1. Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified array of DataRow objects.
2. Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataSet.
3. Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataTable.
4. Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified array of DataRow objects.
5. Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the DataSet with the specified DataTable name.
NOTE:This example uses one of the overloaded versions of Update. For other examples that may be available, see the individual overload topics.
public DataSet UpdateDemo ( DataSet myDataSet, string connString,
string strQuery, string myTableName ) {
OleDbConnection myConn = new OleDbConnection ( connString );
OleDbDataAdapter myAdapter = new OleDbDataAdapter ( );
myAdapter.SelectCommand = new OleDbCommand ( strQuery, myConn );
OleDbCommandBuilder custCB = new OleDbCommandBuilder ( myAdapter );
myConn.Open ( );
DataSet myDataSet = new DataSet ( );
myAdapter.Fill ( myDataSet );
// ... code to modify data in DataSet here ...
// without the OleDbCommandBuilder this line would fail
myAdapter.Update ( myDataSet,"Categories" );
myConn.Close ( );
return myDataSet;
}
Public Function UpdateDemo ( myDataSet As DataSet,
connString As String, strQuery As String, myTableName As String )
As DataSet
Dim myConn As New OleDbConnection ( connString )
Dim myAdapter As New OleDbDataAdapter ( )
myAdapter.SelectCommand = New OleDbCommand ( strQuery, myConn )
Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder ( myAdapter )
myConn.Open ( )
Dim myDataSet As DataSet = New DataSet
myAdapter.Fill ( myDataSet )
' ... code to modify data in DataSet here ...
' Without the OleDbCommandBuilder this line would fail.
myAdapter.Update ( myDataSet,"Categories" )
myConn.Close ( )
Return myDataSet
End Function |
|
C# |
VB |
DbDataAdapter Members