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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.