The solution was found.
Where this was my SQL statement:
The correct statement was:Code:INSERT INTO tblClients (First Name, Last Name) VALUES (?,?)
Code:INSERT INTO tblClients (First_Name, Last_Name) VALUES (?,?)
|
|
Alright, I admit that I have a similar post in the MS Access section, but I feel that the problem that I am having relies between the data adapter and the command builder =\
da=data adapter
ds=dataset
The Insert command that the message box displays looks fine, I can see no syntax errors in it, and yet the program crashes on the update lineCode:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source = Single.mdb" con.Open() sql = "SELECT * FROM tblClients" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "AddressBook") con.Close() Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click If inc <> -1 Then Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow MsgBox(cb.GetInsertCommand.CommandText) da.InsertCommand = cb.GetInsertCommand da.UpdateCommand = cb.GetUpdateCommand da.DeleteCommand = cb.GetDeleteCommand dsNewRow = ds.Tables("AddressBook").NewRow() dsNewRow.Item(0) = 3 dsNewRow.Item(1) = txtFirstName.Text dsNewRow.Item(2) = Date.Now ds.Tables("AddressBook").Rows.Add(dsNewRow) da.Update(ds, "AddressBook") MsgBox("New Record added to Database") btnCommit.Enabled = False btnAddNew.Enabled = True btnUpdate.Enabled = True btnDelete.Enabled = True End If End Sub
I will be more than happy to provide any other needed information, I am quite at a loss for what to do next. This problem has been a thorn in my side for a while -_-Code:da.update(ds, "AddressBook")
The solution was found.
Where this was my SQL statement:
The correct statement was:Code:INSERT INTO tblClients (First Name, Last Name) VALUES (?,?)
Code:INSERT INTO tblClients (First_Name, Last_Name) VALUES (?,?)
Just an FYI...
Pretty sure you could also have just enclosed the field names in brackets.
That should force them to be recognized as field names.Code:INSERT INTO tblClients ([First Name], [Last Name]) VALUES (?,?)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks