将 SQL 中的选定值打印到文本框 VB6
我正在尝试打印 VB6 中的查询中选定的值,这是我的代码
dim query as string
dim stsstring as string
dim rs as adobd.recordset
query = "select status from x where y='"& randomString &"'"
set rs = mainmodule.dbutils.dbconnection.connection.execute(query)
set rs = nothing
stsstring = rs.fields("status")
msgbox stsstring
,我在这里收到错误
stsstring = rs.fields("status")
未设置对象变量或块变量
提前致谢!
I am trying to print the selected value from a query in VB6 this is my code
dim query as string
dim stsstring as string
dim rs as adobd.recordset
query = "select status from x where y='"& randomString &"'"
set rs = mainmodule.dbutils.dbconnection.connection.execute(query)
set rs = nothing
stsstring = rs.fields("status")
msgbox stsstring
I get error here
stsstring = rs.fields("status")
Object variable or with block variable not set
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在尝试从中读取状态字段之前,您已将 rs 设置为空。重新排序您的代码以读取:
You've set rs to nothing before trying to read the status field from it. Re-order your code to read:
以下两种方法都有效,但为了完全安全起见:
规避字符串的
If Not IsNull()
条件的一个简单方法是使用stsstring = vbNullString & rs("状态").value
Both of the below work, but to be completely on the safe side:
An easy way to circumvent the
If Not IsNull()
condition for strings is to usestsstring = vbNullString & rs("status").value