.net – 位置0没有行

前端之家收集整理的这篇文章主要介绍了.net – 位置0没有行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
cmd.CommandText = "select * from product where prod_code='" & Trim(txtprod_code.Text) & "' and branch='" & w_location & "' and avail_stock <>" & (0) & ""
cmd.CommandType = CommandType.Text
con.Open()
da_uqc.SelectCommand = cmd
cmd.Connection = con
da_uqc.Fill(ds_uqc)
m_qty = ds_uqc.Tables(0).Rows(0)(4) 'error 
da_uqc.Dispose()
ds_uqc.Dispose()
cmd.Dispose()

是否有可能像这样给出m_qty = ds_uqc.Tables(0).Rows(0)(4)?

解决方法

您得到一个运行时错误,表示表中根本没有行,因为您的查询字符串没有获得任何匹配的行,您可以先检查行计数:

If ds_uqc.Tables(0).Rows.Count > 0 then
    m_qty = ds_uqc.Tables(0).Rows(0)(4)
End If

P.S:在VB.Net中的评论,以’而不是C#.Net一个//开头.

猜你在找的VB相关文章