Start New Discussion within our Software Development Community

when i use this code to save my datatable to the databaseit works well on the initial save save but when I access the database fill the datatable and then I delete some rows from the datatable and the "SAVE" the changes are not carried on to the database.How come the changes are not reflecting in the database? what can I do ?

    '***************************************************************************************
    '******  SAVE PRODUCT RAW MATERIAL DETAILS IN THE GRIDVIEW *****************************
    Dim myConn As OleDbConnection = frmLogIn.Conn
    Dim oledbCmdBuilder As OleDbCommandBuilder
    Dim changes As DataTable
    Dim sql As String = "select * from ProductRawMaterial"
    Dim oledbAdapter As OleDbDataAdapter = New OleDbDataAdapter(sql, myConn)
    oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter)
    changes = myTable.GetChanges()
    oledbCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges
    If changes IsNot Nothing Then
        oledbAdapter.Update(myTable)
    End If
    myConn.Close()
    '********************************************************************************
    '****************    SAVING TO AUDIT   ******************************************
    Dim myKonn As OleDbConnection = frmLogIn.Connn
    Dim oledbCmdBuilderAudit As OleDbCommandBuilder
    Dim sqlAudit As String = "select * from ProductRawMaterial"
    Dim oledbAdapterAudit As OleDbDataAdapter = New OleDbDataAdapter(sqlAudit, myKonn)
    oledbCmdBuilderAudit = New OleDbCommandBuilder(oledbAdapterAudit)
    oledbCmdBuilderAudit.ConflictOption = ConflictOption.OverwriteChanges
    If changes IsNot Nothing Then
        oledbAdapterAudit.Update(changes)
    End If
    myKonn.Close()

Be sure to call MyDataSet.AcceptChanges. This tells the underlying class that changes have been made. It also validated the changes. Then call DataAdapter.Update.

This article has been dead for over six months. Start a new discussion instead.