Error: INSERT INTO Customer(Cust_ID, Name, Address, Username, Password) VALUE(?,?,?)
Hello everyone,
Please can someone help me to debug this error? It has been giving me a huge headache since last night. Anytime I try to add new record into my database, this error message keeps coming up: "Error: INSERT INTO Customer(Cust_ID, Name, Address, Username, Password) VALUE(?,?,?,?,?,?)". I don't know where the problem lies.
Here's my code for the "add/commit" button:
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
MessageBox.Show(cb.GetInsertCommand.CommandText)
da.InsertCommand = cb.GetInsertCommand
'da.UpdateCommand = cb.GetUpdateCommand
'da.DeleteCommand = cb.GetDeleteCommand
dsNewRow = ds.Tables("SouthCity").NewRow()
dsNewRow.Item(0) = txtCustID.Text
dsNewRow.Item(1) = txtCUstName.Text
dsNewRow.Item(2) = txtAddress.Text
dsNewRow.Item(3) = txtTelNo.Text
dsNewRow.Item(4) = txtUsername.Text
dsNewRow.Item(5) = txtPassword.Text
ds.Tables("SouthCity").Rows.Add(dsNewRow)
da.Update(ds, "SouthCity")
End If
End Sub
tomexlfc,
Did you use a SELECT Command on your DataAdapter to fill your Dataset Table? After you make the Adapter.Fill(DataSet,Table) you can get the Update,Insert, and Delete Commands for your DataAdapter via the CommandBuilder.
Please can someone help me to debug this error? It has been giving me a huge headache since last night. Anytime I try to add new record into my database, this error message keeps coming up: "Error: INSERT INTO Customer(Cust_ID, Name, Address, Username, Password) VALUE(?,?,?,?,?,?)". I don't know where the problem lies.
Here's my code for the "add/commit" button:
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
MessageBox.Show(cb.GetInsertCommand.CommandText)
da.InsertCommand = cb.GetInsertCommand
'da.UpdateCommand = cb.GetUpdateCommand
'da.DeleteCommand = cb.GetDeleteCommand
dsNewRow = ds.Tables("SouthCity").NewRow()
dsNewRow.Item(0) = txtCustID.Text
dsNewRow.Item(1) = txtCUstName.Text
dsNewRow.Item(2) = txtAddress.Text
dsNewRow.Item(3) = txtTelNo.Text
dsNewRow.Item(4) = txtUsername.Text
dsNewRow.Item(5) = txtPassword.Text
ds.Tables("SouthCity").Rows.Add(dsNewRow)
da.Update(ds, "SouthCity")
End If
End Sub
tomexlfc,
Did you use a SELECT Command on your DataAdapter to fill your Dataset Table? After you make the Adapter.Fill(DataSet,Table) you can get the Update,Insert, and Delete Commands for your DataAdapter via the CommandBuilder.