Update Not reflecting to Access Database

Hi All,

I am using DataGridView to show table data and allowing user to add/update/delete
its content. I am manually creating sql on the basis of a value in a list box and getting the data through the following code:

--------------------------------------------------------------------------------------------------

Dim sql As String = "SELECT fldAssetID, fldCategoryID, fldAssetName, fldDescription, fldDateAcquired, fldCost FROM tblAssets where fldCategoryID = " & lst_AssetCategories.SelectedValue
Dim cmd As OleDbCommand = New OleDbCommand(sql, Conn)
myDataAdapter =
New OleDbDataAdapter(cmd)
myDataSet.Clear()
myDataAdapter.Fill(myDataSet,
"tblAssets")
dgv_AssetDetails.DataSource = myDataSet
dgv_AssetDetails.DataMember =
"tblAssets"

---------------------------------------------------------------------------------------------------------------------------

and the code behind update button handler is :

--------------------------------------------------------------------------------------------------------------------------

Dim myCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
Dim dsChanged As DataSet = myDataSet.GetChanges()

If Not (dsChanged Is DBNull.Value) Then

myDataAdapter.Update(dsChanged, "tblAssets")

dsChanged.AcceptChanges()

MessageBox.Show("Changes have been saved to Database")

End If

--------------------------------------------------------------------------------------------------------------------------
Class Variables :

Shared Conn As OleDbConnection = New OleDbConnection(WindowsApplication1.My.MySettings.Default.ITP400_IP2_AConnectionString)
Dim myDataAdapter As OleDbDataAdapter
Dim myDataSet As DataSet = New DataSet("myDataSet")
-------------------------------------------------------------------------------------------------------------------------

The update event goes fine and if I try to get data again in the same session, I get the updated data
but the data is not reflecting in the database, so thats why if I exit the application and rerun it
it doesnt shows the updated data.

Thanks In Advance

Adil



Answer this question

Update Not reflecting to Access Database

  • RandomLick

    You can try calling EndEdit on the DataGridView, also perhaps someone here who is better then me with VB can verify your logic to see if there were changes.

    HTH!



  • fschaller

     

    Thanks Paul ,

                        It helped, it was the same problem of copying older databse file from the project main folder to the data directory by the visual studio every time we run application, although the application was updating the database properly.

    Best Regards

    Adil


  • John12312

    well thats what OleDbCommandBuilder is doing for me, it creates insert,update and delete commands in DataAdapter.

    Thanks
    Adil


  • uanmi

    Seems like u didn't define the DataAdapter properly.

    To use Update method of DataAdapter you have to define InsertCommand, UpdateCommand and DeleteCommand of the DataAdapter



  • AyendeRahien

    Try putting a breakpoint on

    myDataAdapter.Update(dsChanged, "tblAssets")

    When it stops there put the mouse over dsChanged, and explore the object. Make sure it has rows.



  • pharaonix

  • Update Not reflecting to Access Database