开发者

OLEdbcommand.Prepare error

开发者 https://www.devze.com 2023-01-08 19:27 出处:网络
I am getting an error: OleDbCommand.Prepare method requires all parameters to have an explicitly set type.

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.I开发者_开发技巧tem("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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号