vig*_*esh 3 .net vb.net ado.net exception-handling
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()
Run Code Online (Sandbox Code Playgroud)
有可能这样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
Run Code Online (Sandbox Code Playgroud)
PS: VB.Net中的评论,从'C#.Net 开始,而不是C#.Net //.