开发者

Error: Conversion from type DBNull to type string is not valid

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 app开发者_StackOverflow中文版ear 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.??


There are a few issues.

  1. Your query is a bit off. It currently reads Select Quantity from tlist where tool_name'valueOfListbox2'". It should probably read Select Quantity from tlist where tool_name = 'valueOfListbox2'.
  2. 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

  3. Also, you're missing a double quote around "Quantity".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜