Calls the respective insert, update, or delete commands on the connection, for each inserted, updated, or deleted rows in the data set.
Calls the respective insert, update, or delete commands on the connection, for each inserted, updated, or deleted rows in the data set for a given source table.
[Visual Basic] Overloads Overridable Public Function Update(DataRow()) As Integer
[C#] public virtual int Update(DataRow[]);
[C++] public: virtual int Update(DataRow*[]);
[JScript] public function Update(DataRow[]) : int;
Calls the respective insert, update, or delete commands on the connection, for each inserted, updated, or deleted rows in the data set for a given source table.
[Visual Basic] Overloads Overridable Public Function Update(DataSet, String) As Integer
[C#] public virtual int Update(DataSet, String);
[C++] public: virtual int Update(DataSet*, String);
[JScript] public function Update(DataSet, String) : int;
Calls the respective insert, update, or delete commands on the connection for each inserted, updated, or deleted row in the data set for the given DataSet.
[Visual Basic] Overloads Overrides Public Function Update(DataSet) As Integer
[C#] public override int Update(DataSet);
[C++] public: override int Update(DataSet*);
[JScript] public override function Update(DataSet) : int;
The following example creates and initializes a DataSet and an ADODataSetCommand. The example then uses the Update method to update the DataSet and the data source.
Note This example shows how to use one of the overloaded versions of Update. For other examples that may be available, see the individual overload topics.
[Visual Basic]
Sub CreateAndUpdateDataSet() Const strConnection = "Provider=SQLADO.1;User ID=sa;PASSWORD=;" _ + "Initial Catalog=Northwind;Data Source=vbsql7;" Const strSelectCommand = "SELECT intID, vchFirstName, vchLastName, " _ + "chState FROM Customers WHERE chState = 'CA'" Const strUpdateCommand = "UPDATE tblCustomer SET vchFirstName = ?, " _ + "vchLastName = ?, chState = ? WHERE intID = ?" Dim dataSet As DataSet Dim adoConnection As ADOConnection Dim adoDataSetComm As ADODataSetCommand Dim adoParam As ADOParameter ' Initialize the DataSet Set dataSet = New DataSet ' Initialize the connection Set adoConnection = New ADOConnection(strConnection) ' Initialize the new ADODataSetCommand object Set adoDataSetComm = New ADODataSetCommand ' Set the table that the ADODataSetCommand is to map to adoDataSetComm.TableMappings.Add "Customers", "Customer" ' Set the select command Set adoDataSetComm.SelectCommand.CommandText = strSelectCommand ' Set the active connection for our ADODataSetCommand Set adoDataSetComm.SelectCommand.ActiveConnection = adoConnection ' Populate the DataSet adoDataSetComm.FillDataSet dataSet, "Customers" ' Set the command text to the text of the query adoDataSetComm.UpdateCommand.CommandText = strUpdateCommand ' Set the command's connection to the current connection Set adoDataSetComm.UpdateCommand.ActiveConnection = adoConnection ' Set any parameters for this command Set adoParam = adoDataSetComm.UpdateCommand.parameters.Add( _ "vchFirstName", ADODBType.VarChar, 50) adoParam.SourceColumn = "vchFirstName" Set adoParam = adoDataSetComm.UpdateCommand.parameters.Add( _ "vchLastName", ADODBType.VarChar, 50) adoParam.SourceColumn = "vchLastName" Set adoParam = adoDataSetComm.UpdateCommand.parameters.Add( _ "chState", ADODBType.Char, 2) adoParam.SourceColumn = "chState" Set adoParam = adoDataSetComm.UpdateCommand.parameters.Add( _ "intID", ADODBType.Integer) adoParam.SourceColumn = "intID" ' this uses the UPDATE statement above adoConnection.BeginTransaction Try ' Update the data source with changes made in dataSet adoDataSetComm.Update dataSet adoConnection.CommitTransaction Catch e As Exception Dim displayBox As New MessageBox displayBox.Show "Error while updating data source - rolling back transaction..." adoConnection.RollbackTransaction End Try adoConnection.close End Sub
DBDataSetCommand Class | DBDataSetCommand Members | System.Data.Internal Namespace