I currently have a Microsoft Access database which is being accessed through an ASP .NET front end. I am trying to add a row to a table, but this doesn't appear to be working, the code I am using is shown below.
Sub prcChoose()
Dim sql As String
Dim da As New OleDbDataAdapter
Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim cb As New OleDbCommandBuilder(da)
ds = New DataSet
conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("dbConnection").ConnectionString)
sql = "SELECT * FROM ParentPreference"
conn.Open()
da = New OleDbDataAdapter(sql, conn)
da.Fill(ds, "Choice")
Dim NewRow As Data.DataRow = ds.Tables("Choice").NewRow()
NewRow.Item(0) = txtUser.Text
NewRow.Item(1) = dropdown.SelectedValue
ds.Tables("Choice").Rows.Add(NewRow)
***da.UpdateCommand = cb.GetUpdateCommand()***
da.Update(ds, "Choice")
End Sub
I receive different error messages depending on whether or not the line enclosed by 3 asterisks is included. Without it I receive "Update requires a valid InsertCommand when passed DataRow collection with new rows." and with it I receive "The DataAdapter.SelectCommand property needs to be initialized." I have spent hours trying to figure out where I'm going wrong and I haven't had any success.
Thanks in advance!
EDIT: On the advice of Casey below I added the following lines of code:
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
I added these lines just below the code enclosed by asterisks above. But I still receive the same error message. The DataAdapter.SelectCommand property needs to be initialized. This error occurs on the following line
da.InsertCommand = cb.GetInsertCommand