没有给出vb.net中一个或多个必需参数的值

时间:2012-06-05 05:38:14

标签: vb.net

我收到了这个错误

  

没有给出一个或多个必需参数的值

我的代码的这部分

Private Sub RefreshData()
    con.Open()

    cmd.CommandText = ("SELECT pCode as [ID], lampname as [NAME],  costumer, proddate, line/shift, watts, volts, filam, base, basepos,lumen, life, atm, fuse, exp, type,testCode, textVolt, samplesize, dateStart, timeStart, LNWatts1, LNWatts2, LNWatts3, LNWatts4, LNWatts5, LNLumen1, LNLumen2, LNLumen3, LNLumen4, LNLumen5, LPW1, LPW2, LPW3, LPW4, LPW5, RLWatts1, RLWatts2, RLWatts3, RLWatts4, RLWatts5, RLLumen1, RLLumen2, RLLumen3, RLLumen4, RLLumen5, LPWF1, LPWF2, LPWF3, LPWF4, LPWF5, InspectionTime1, InspectionTime2, InspectionTime3, InspectionTime4, InspectionTime5, InspectionDate1, InspectionDate2, InspectionDate3, InspectionDate4, InspectionDate5, TH1, TH2, TH3, TH4, TH5, EL1, EL2, EL3, EL4, EL5, Dispo1, Dispo2, Dispo3, Dispo4, Dispo5, CF1, CF2, CF3, CF4, CF5, Reason1, Reason2, Reason3, Reason4, Reason5, LNAve1, LNAve2, LNAve3, LNAve4, LNAve5, LNAve6, LNAve7, LNAve8, LNAve9, LNAve10, LNAve11, LNAve12, LNAve13, LNsd1, LNsd2, LNsd3, LNsd4, LNsd5, LNsd6, LNsd7, LNsd8, LNsd9, LNsd10, LNsd11, LNsd12, LNsd13, TorqueTest, zeroHour, EndOfLife, PFCPTime1, PFCPTime2, PFCPTime3, PFCPTime4, PFCPTime5, PFCPDate1, PFCPDate2, PFCPDate3, PFCPDate4, PFCPDate5, BatchNumber FROM records ORDER by ID")

    Dim da As New OleDbDataAdapter
    Dim dt As New DataTable

    da.SelectCommand = cmd
    da.Fill(dt)   -- I get the error right here

    con.Close()
End Sub

那会有什么问题?希望有人帮忙,我只是vb.net的新手..

谢谢。

1 个答案:

答案 0 :(得分:1)

尝试在/字符

的字段周围放置括号
proddate, [line/shift], watts, etc...

否则,您必须痛苦地确保在SQL字符串中键入的每个字段实际存在于[records]表中。

考虑到查询中的字段数量,我认为只做SELECT * FROM [records] ORDER BY pCode就足够了。

另外,请确保在order子句中使用实际字段名称:

ORDER BY pCode