OLEdbcommand.Prepare错误 [英] OLEdbcommand.Prepare error

查看:100
本文介绍了OLEdbcommand.Prepare错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误:

OleDbCommand.Prepare方法要求所有参数都具有显式设置的类型.

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)

推荐答案

,您需要在此处指定参数类型.而不是这样:

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)

使用此方法:

// 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;

希望有帮助.

这篇关于OLEdbcommand.Prepare错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆