I presently possess a Microsoft Access database that is being utilized with an ASP .Internet front-end. I'm attempting to give a row to some table, but this does not seem to be working, the code I'm using is proven 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 based on set up line enclosed by 3 asterisks is incorporated. Without them I receive "Update takes a valid InsertCommand when passed DataRow collection with new rows." with it I receive "The DataAdapter.SelectCommand property must be initialized." I've spent hrs trying to puzzle out where I am failing and that i haven't had any success.

Thanks ahead of time!

EDIT: Around the advice of Casey below I added the next lines of code:

    da.InsertCommand = cb.GetInsertCommand
    da.DeleteCommand = cb.GetDeleteCommand

I added wrinkles just beneath the code enclosed by asterisks above. However I still get the same error message. The DataAdapter.SelectCommand property must be initialized. This error happens around the following line

da.InsertCommand = cb.GetInsertCommand

Shooting from memory because I can not presently reach Visual Studio to check on your code, but..

You will find several instructions the Data Adapter needs to be able to update/remove/place for your Access table. It appears as if you used an order Builder to construct the Update command, that the Data Adapter uses for rows that require upgrading. Additionally, you should also make use of the Command Builder to construct Place and Remove instructions:

da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand

The "Update takes a valid InsertCommand" error is suggesting the Data Adapter doesn't understand how to place the brand new rows you produced in Data Table towards the Access DB since you haven't told it what Place Command to make use of. Placing the 2 lines above should fix this problem.

The InsertCommand, DeleteCommand, and UpdateCommand around the Data Adapter are simply SQL claims the Data Adapter uses to improve your underlying databases, within this situation Access. You are able to by hand supply these instructions or make use of the CommandBuilder for straightforward cases like that one.

Whenever you tell the DataAdapter to Update, it loops with the Data Table as well as for each row determines in the event that row continues to be added, erased, or up-to-date. After that it searches for the right command to complete the SQL statement to Place, Remove, or Update. Should you haven't provided the command, you receive the mistake you're seeing.

EDIT: Here's your code up-to-date to repair the "SelectCommand not initialized" error along with a couple of other activities:

Sub prcChoose()

    'Always create disposable objects with a Using statement.
    'This ensures that the objects will be disposed properly.
    Using conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("dbConnection").ConnectionString), _
        da As New OleDbDataAdapter("SELECT * FROM ParentPreference", conn), _
        cb As New OleDbCommandBuilder(da)

        'Open connection.
        conn.Open()

        'Create new dataset.
        Dim ds As New DataSet

        'Fill dataset.
        da.Fill(ds, "Choice")

        'Create new row and populate it.
        Dim NewRow As Data.DataRow = ds.Tables("Choice").NewRow()
        NewRow.Item(0) = txtUser.Text
        NewRow.Item(1) = dropdown.SelectedValue

        'Add row to Choice table.
        ds.Tables("Choice").Rows.Add(NewRow)

        'Use command builder to generate Update, Insert, Delete commands for DataAdapter.
        da.UpdateCommand = cb.GetUpdateCommand
        da.InsertCommand = cb.GetInsertCommand
        da.DeleteCommand = cb.GetDeleteCommand

        'Use dataadapter to update datasource.
        da.Update(ds, "Choice")


    End Using

End Sub