Im doing a program that connects a form to access database.
Problem: I have a button that saves all the new information entered in the text boxes I have. When I click SAVE it shows a message that "A new record has been added to the database" but when I look in the database..its not there..


thanks in advance

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
con = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\God\My Documents\Visual Studio Projects\test\HostingDB.mdb")
da = New OleDb.OleDbDataAdapter("SELECT * FROM tblContact1", con)
If inc <> -1 Then
Dim drow As DataRow
Dim dcmdbuilder As New OleDb.OleDbCommandBuilder(da)
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
da.Fill(ds, "HostingDB")
drow = ds.Tables("HostingDB").NewRow()
drow("ID") = txtCiD.Text + 1
drow("CName") = txtCName.Text
drow("PCont") = txtPCont.Text
da.Update(ds, "HostingDB")
MsgBox("New record added to the database")
End If
btnSave.DialogResult = DialogResult.OK
btnUpdate.Visible = True
btnUpdate.Enabled = True
btnNew.Visible = True
btnNew.Enabled = True
btnDel.Visible = True
btnDel.Enabled = True
btnSave.Visible = False
btnCancel.Visible = False
End Sub

Have you doulbe checked your "alias" names for the columns you are populating. One thing to also do is the use the GetChanges() method of the dataadpter to see if you are getting the row(s) you added returned.

I checkd everything...

I tried creating another version of this as a "TEST" (less columns) it worked on it...SAME CODING and stuff..
but this one seems to be not working.

-maybe its the database fault??

is ther like a LIMIT for columns in a connection or something???


You have to get rid of your line ds.AcceptChanges.

You need to do this because ds.AcceptChanges will turn all of your rows in the dataset to datarowstate.Unchanged. Which means that when you do the da.Update there are no records to update.

If you need more information on this let me know.

Thank you,


Thanks vbismee....but when I take out ds.Acceptchanges .......an error shows up........to the da.Update(ds, "HostingDB")....

Error: Syntax ERROR in INSERT INTO Statement....

Is the ID column an AutoNumber?
If it is you should not set the ID column when you add the row.
If not then what is the rest of the error code?

If you want to talk to quicker, send me a private message and I will send you my email address.

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