cmd.CommandText = "select * from product where prod_code='" Trim(txtprod_code.Text) "' and branch='" w_location "' and avail_stock " (0) ""cmd.CommandType = CommandType.Textcon.Open()da_uqc.SelectCommand = cmdcmd.Connection = conda_uqc.Fill
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一个//开头.