Saving changes made in a DataGridView to an Access Database

crazymarvin

Member
Joined
Nov 22, 2006
Messages
18
Location
Belfast, UK
Programming Experience
Beginner
Hi, I cant figure out how to update my database with changes made in the datagrid view.

I am useing the following code to fill the datagridview:
VB.NET:
     Dim dsContacts As New DataSet
    Dim connstr As String = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MTA.mdb;Persist Security Info=True;Jet OLEDB:Database Password=62685526"
    Dim strSQL_Contacts As String = "Select * FROM tblContacts WHERE C_Staff = False"
    Dim daContacts As New OleDb.OleDbDataAdapter(strSQL_Contacts, connstr)
    Dim cbContacts As New OleDb.OleDbCommandBuilder(daContacts)

       strSQL_Contacts = "Select * WHERE C_Staff=False"
        daContacts = New OleDb.OleDbDataAdapter(strSQL_Contacts, connstr)
        dsContacts = New DataSet
        daContacts.Fill(dsContacts, "tblContacts")

        dgvMain.DataSource = dsContacts
        dgvMain.DataMember = "tblContacts"

I was attempting to use the following code to save:
VB.NET:
daContacts.Update(dsContacts, "tblContacts")

I know im missing something, but i cant figure out what. Can anyone help?
 
That's exactly what you do. Check the value returned by the Update function. If it's greater than zero then your data is being saved.

Let me guess. You're quitting the app and then running it again and there's no data, right? That's because you're overwriting your database every time you run the project. Read this.
 

Latest posts

Back
Top