【问题标题】:no value given for one or more required parameters in vb.netvb.net 中的一个或多个必需参数没有给出值
【发布时间】:2012-06-06 04:42:53
【问题描述】:

我收到了这个错误

没有为一个或多个必需参数指定值

在我的这部分代码

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的新手..

谢谢。

【问题讨论】:

  • 我猜您在某处拼错了字段名称。如果数据库中不存在该字段,则 SQL Server 假定它是一个参数。正如 LarsTech 下面所说,行/班次可能是罪魁祸首 - 将其括在方括号中。

标签: vb.net


【解决方案1】:

尝试在带有/ 字符的字段周围加上括号

proddate, [line/shift], watts, etc...

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

鉴于您查询中的字段数量,我认为只需执行 SELECT * FROM [records] ORDER BY pCode 就足够了。

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

ORDER BY pCode

【讨论】:

  • @DerickBaquilodOperario 试过什么?括号或Select * ?
  • @DerickBaquilodOperario 更新了答案。我刚刚再次查看了您的查询。 ORDER BY 引用了 ID,但 ID 只是一个别名。尝试将其切换为ORDER BY pCode
猜你喜欢
  • 2022-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多