I am having trouble inserting records into my database from a form with textboxs.

Here is the code for the add button however data is not adding to the database.

If inc <> -1 Then

Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow

dsNewRow = ds.Tables("AddressBook").NewRow()

dsNewRow.Item("FirstName") = txtfirstname.Text
dsNewRow.Item("Surname") = txtsurname.Text

ds.Tables("AddressBook").Rows.Add(dsNewRow)

da.Update(ds, "AddressBook")

MsgBox("New Record added to the Database")

btncommit.Enabled = False
btnadd.Enabled = True
btmupdate.Enabled = True
btndelete.Enabled = True

End If

I would be greatefull this someone could tell me where i am goin wrong.

Thanks

Welcome Rtailor,

Did you read How to post source code using bb code tags?.

Wrap up source code with code tag.
Here is an example:

If inc <> -1 Then
    Dim cb As New OleDb.OleDbCommandBuilder(da)
    Dim dsNewRow As DataRow
    
   dsNewRow = ds.Tables("AddressBook").NewRow()
   dsNewRow.Item("FirstName") = txtfirstname.Text
   dsNewRow.Item("Surname") = txtsurname.Text

   ds.Tables("AddressBook").Rows.Add(dsNewRow)

   da.Update(ds, "AddressBook")

   MsgBox("New Record added to the Database")

   btncommit.Enabled = False
   btnadd.Enabled = True
   btmupdate.Enabled = True
   btndelete.Enabled = True
End If

Answer the question:
1. Is Fill method of DataAdapter used?
2. Your table must have a primary key. Is there?

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