错误:从 DBNull 类型到 string 类型的转换无效
我又来解决问题了。请帮助我做到这一点。我试图利用列表框中的选择从数据库获取数量。我得到了 listbox1 的答复。如果我选择列表框 1 中的项目,数量将出现在文本框 1 中。但在这段相同的代码中,对于带有 textbox4 的 listbox2 不起作用。这里我给出了代码...
$Con.open()
$Dim cd as new oledb.oledbcommand("Select Quantity from tlist where tool_name"& "'"listbox2.selecteditem & "'" & "", con)
$dim rs as oledb.oledbdatareader
$do while rs.read
$textbox4.text=(rs("Quantity))
$loop
$con.close
这里我收到错误“从 DBNull 类型到字符串类型的转换无效”,请让我知道我该怎么办。? ?
again i came for a problem. Please help me to do this. I was tried to get quantity from db make use of the selection in list box. I got answered with listbox1. If i selected the item in listbox1 the quantity would appear in textbox1. But in this same code will not work for listbox2 with textbox4.. Here i given the code...
$Con.open()
$Dim cd as new oledb.oledbcommand("Select Quantity from tlist where tool_name"& "'"listbox2.selecteditem & "'" & "", con)
$dim rs as oledb.oledbdatareader
$do while rs.read
$textbox4.text=(rs("Quantity))
$loop
$con.close
Here i got the error as "Conversion from type DBNull to type string is not valid" Plz let me know what will i do.??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几个问题。
您得到的是 null值返回并且在写出值之前不检查是否返回 null,因此您可以使用以下 IF 语句来验证您的值不为 null:
如果 NOT IsDbNull(rs("Quantity")) 那么
此外,您还缺少“Quantity”周围的双引号。
There are a few issues.
Your getting a null value back and are not checking for a null return before writing the value out, hence the error. You can use the following IF statement to verify your value is not null:
If NOT IsDbNull(rs("Quantity")) Then
Also, you're missing a double quote around "Quantity".