Hi,
Consider the following scenario
I have a Database source i had filled in my dataset with the help of Dataadapter
after working on the dataset i want the data source to be updated back with the new data available with me.
It may be a small change in the employee_name column for example.
And if the data had already been modified even deleted by some other user of the database then my dataset update method will prone to some error.
How to synchronize the dataset with the datasource before updating the datasource.
Thanks,
Krish
Hi,
a. Opening a Connection.
b. Instantiate the Commands.
c. Instantiate the DataAdapter.
d. Setting the DataAdapter command properties.
myAccountAdapter.SelectCommand = comAccountSelect
myAccountAdapter.InsertCommand = comAccountInsert
myAccountAdapter.DeleteCommand = comAccountDelete
myAccountAdapter.UpdateCommand = comAccountUpdate
e. Add Select Command parameters.
f. Add Insert Command parameters.
Ex:
comAccountInsert.Parameters.Add(“@id”, SqlDbType.Char, 6, “AccountCode”)
comAccountInsert.Parameters.Add(“@name”, SqlDbType.Char, 30, “AccountName”)
g.Add Update Command parameters.
h. Add Delete Command parameters.
i. Instantiate the DataSets.
When we are finished with manipulating data in the DataSet, it is time to update the DataSource. This is done using the Update method of the DataAdapter class. This method is responsible for examining the RowState property of each of the DataRow objects in the Rows collection. The Rows Collection is a member of each of the DataTable objects contained in the Tables collection of the dataset.
Private Sub UpdateDatabaseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateDatabaseButton.Click
Dim i As Integer
myConnection.Open()
For i = 0 To (myAccountDataset.Tables(“AccountsTable”).Rows.Cou nt() - 1)
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(0))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(1))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(2))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(3))
Next
myAccountAdapter.Update(myAccountDataset.GetChange s, “AccountsTable”)
End Sub
End Class
TRy this book Titled:"Database programming using vb.net and sqlserver"
[Link Removed]