vba 没有为一个或多个必需参数给出值 视觉基本错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17651091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:09:32  来源:igfitidea点击:

No value given for one or more required parameters visual basic error

vbavb6

提问by dapinder

This error is appearing in following line of the vb code

此错误出现在 vb 代码的以下行中

 rs.Open "select * From Reservation where [table_number]=tablenumber.text and booking_date=bookingdate.Text", cn, adOpenStatic, adLockPessimistic

回答by MicSim

It's a problem with your SQL query. The reason for the message is that the SQL parser can't identify a token in your SQL query and interprets it as a parameter for which you need to provide a value.

这是您的 SQL 查询的问题。该消息的原因是 SQL 解析器无法识别您的 SQL 查询中的标记并将其解释为您需要为其提供值的参数。

So, you either mistyped some of your field or table names, or you created your SQL the wrong way. I suppose the latter and it should read

因此,您要么打错了某些字段名或表名,要么以错误的方式创建了 SQL。我想后者应该读

 rs.Open "select * From Reservation where [table_number] = " & tablenumber.text & " and booking_date=" & bookingdate.Text, cn, adOpenStatic, adLockPessimistic

because tablenumberand bookingdateare very likely form controls.

因为tablenumber并且bookingdate很可能是表单控件。

The above query won't work out of the box as you need to use the correct data types for the SQL query which I cannot infer based on your sparse information.

上面的查询无法立即使用,因为您需要为 SQL 查询使用正确的数据类型,我无法根据您的稀疏信息推断出该类型。

回答by Ravi Chandran

If you are INSERTing values in TABLE - dont miss enclosing it in single quotes, like ' " & text1.text & " '

如果您INSERT在 TABLE中输入值 - 不要错过将其括在单引号中,例如 ' " & text1.text & " '

example:

例子:

INSERT into [TABLE NAME]([Purchase Order Status]) values(' " & text1.text & " ')

回答by Dale

I would suggest adding () around the selection criteria:

我建议在选择标准周围添加 ():

rs.Open "select * From Reservation where ( [table_number]=tablenumber.text and booking_date=bookingdate.Text )"