Explain the DataAdapter.Update() and DataSetAcceptChanges() methods.

 Posted by Bharathi Cherukuri on 5/21/2012 | Category: ADO.NET Interview questions | Views: 3786 | Points: 40

The DataAdapter.Update() method calls any of the DML statements, such as the UPDATE, INSERT, or DELETE statements, as the case may be to update, insert, or delete a row in a DataSet.


Dim NumberOfRowsUpdated As Integer 

NumberOfRowsUpdated = MyDataAdapter.Update(MyDataSet, "MyCustomer")

The DataSet.Acceptchanges() method reflects all the changes made to the row since the last time the AcceptChanges() method was called.


Private Sub AcceptChanges()

Dim myDataSet As DataSet
myDataSet = new DataSet()

' Not shown: methods to fill the DataSet with data.
Dim t As DataTable

t = myDataSet.Tables("Suppliers")

' Add a DataRow to a table.
Dim myRow As DataRow
myRow = t.NewRow()
myRow("CompanyID") = "NWTRADECO"
myRow("CompanyName") = "NortWest Trade Company"

' Add the row.
t.Rows.Add( myRow )

' Calling AcceptChanges on the DataSet causes AcceptChanges to be
' called on all subordinate objects.
End Sub

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response