我再次检查DataReader对象是否有数据有问题?
Dim cmd as SqlCommand
Dim drd as SqlDataReader
cmd = New SqlCommand ("SELECT * FROM Stock", conx)
drd = cmd.ExecuteReader()
''HERE I WOULD LIKE TO CHECK WHETHER drd has Data or not
While (drd.Read())
{
txtName.Text = drd.Item("StockName")
}
我该怎么检查?请帮我!谢谢大家!
答案 0 :(得分:9)
if(drd.HasRows)
{
//....
}
答案 1 :(得分:1)
是的,你可以使用drd.read()
像:
If drd.read() Then
...do things with data...
Else
...show message box... or just skip.
End If
答案 2 :(得分:0)
drd.Read()将返回False。您无需更改代码。