tags:

views:

19

answers:

1

I am getting an error:

OleDbCommand.Prepare method requires all parameters to have an explicitly set type.

on the last line of the code below. I have seen things saying you have to set the datatype of each parameter but how can i do that when it being generated by the command builder?

I have seen people say they dont like using autogenerated queries, is this a bad way to go about doing what I am trying to do?

        Dim checkDock As New OleDbCommand("SELECT Instance, DocketNumber, FormID, FieldName, Occurrence, FieldValue  FROM fielddata WHERE docketnumber = @dock AND formid = @formid " & _
        "AND instance = @inst1")
        checkDock.Connection = New OleDbConnection("Provider=" & My.Settings.Provider & ";" & "Data Source=" & My.Settings.DataSource1)

        'create and execute the command to retrieve the saved data for the original instance
        checkDock.Parameters.AddWithValue("@dock", dock)
        checkDock.Parameters.AddWithValue("@formid", formid)
        checkDock.Parameters.AddWithValue("@inst1", inst1)

        Dim da As New OleDbDataAdapter(checkDock)

        Dim dSet As New DataSet("copySet")
        da.Fill(dSet)

        'create a command builder to put the new entries in the database
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        Dim rowList As New ArrayList()

        For Each r As DataRow In dSet.Tables(0).Rows

            Dim dRow As DataRow = dSet.Tables(0).NewRow

            dRow.Item("Docketnumber") = dock2
            dRow.Item("Formid") = formid
            dRow.Item("fieldname") = r.Item("fieldname")
            dRow.Item("occurrence") = r.Item("occurrence")
            dRow.Item("fieldvalue") = r.Item("fieldvalue")
            dRow.Item("Instance") = inst2

            rowList.Add(dRow)
        Next

        For Each a As DataRow In rowList
            dSet.Tables(0).Rows.Add(a)
        Next

        da.Update(dSet)
A: 

Hi - you need to specify the parameter types here. Rather than this:

checkDock.Parameters.AddWithValue("@dock", dock)
checkDock.Parameters.AddWithValue("@formid", formid)
checkDock.Parameters.AddWithValue("@inst1", inst1)

Use this method:

// replace ??? with the correct type
checkDock.Parameters.Add("@dock", OleDbType.???).Value = dock;
checkDock.Parameters.Add("@formid", OleDbType.???).Value = formid;
checkDock.Parameters.Add("@inst1", OleDbType.???).Value = inst1;

Hope that helps.

Kieren Johnstone
Those paramaters are usedto pull the data tin from the database. That part works fine. Its after adding the new rows to the dataSet that causes the error when updating. If I remove the code to add the new rows to the dataset the update works fine and doesnt cause en error.
Tim