Dataset.Update synchronization

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Krish2007
    New Member
    • Dec 2006
    • 1

    Dataset.Update synchronization

    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
  • bhar
    Banned
    New Member
    • Apr 2006
    • 37

    #2
    Originally posted by Krish2007
    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.

    myAccountAdapte r.SelectCommand = comAccountSelec t
    myAccountAdapte r.InsertCommand = comAccountInser t
    myAccountAdapte r.DeleteCommand = comAccountDelet e
    myAccountAdapte r.UpdateCommand = comAccountUpdat e

    e. Add Select Command parameters.
    f. Add Insert Command parameters.
    Ex:

    comAccountInser t.Parameters.Ad d(“@id”, SqlDbType.Char, 6, “AccountCode”)
    comAccountInser t.Parameters.Ad d(“@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 UpdateDatabaseB utton_Click(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles UpdateDatabaseB utton.Click
    Dim i As Integer
    myConnection.Op en()
    For i = 0 To (myAccountDatas et.Tables(“Acco untsTable”).Row s.Count() - 1)
    MsgBox(myAccoun tDataset.Tables (“AccountsTable ”).Rows(i)(0))
    MsgBox(myAccoun tDataset.Tables (“AccountsTable ”).Rows(i)(1))
    MsgBox(myAccoun tDataset.Tables (“AccountsTable ”).Rows(i)(2))
    MsgBox(myAccoun tDataset.Tables (“AccountsTable ”).Rows(i)(3))
    Next
    myAccountAdapte r.Update(myAcco untDataset.GetC hanges, “AccountsTable” )
    End Sub
    End Class

    TRy this book Titled:"Databas e programming using vb.net and sqlserver"
    [Link Removed]
    Last edited by Frinavale; Apr 27 '07, 02:44 PM. Reason: Link was removed because it is considered spam and its content is not typical HTML

    Comment

    Working...