VB.Net 检查数据集是否有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22033605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.Net Checking if DataSet has rows or not
提问by user3148632
Private Function Gelobee() As DataSet
Dim connection As OleDb.OleDbConnection = New OleDbConnection
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=CMP.accdb"
connection.Open()
Dim da As OleDb.OleDbDataAdapter = New OleDbDataAdapter("SELECT IDDesc FROM [ItemDesc] WHERE IDPartNo = '" & PartNoTxt.Text & "';", connection)
Dim ds As New DataSet
da.Fill(ds, "FilteredDesc")
connection.Dispose()
connection = Nothing
If ds.Tables.Count > 0 Then
If ds.Tables[0].Rows.Count > 0 Then
DescTxt.Text = ds.Tables(0).Rows(0).Item(0)
Else
DescTxt.Text = "No Description"
End If
End If
Return ds
End Function
Hi, I'm trying to check if the data set has rows. But it's giving me error at "ds.Tables[0].Rows.Count > 0". Anything wrong with my code? I tried to search all over the net but I can't seem to find an answer.
嗨,我正在尝试检查数据集是否有行。但它在“ds.Tables[0].Rows.Count > 0”处给了我错误。我的代码有什么问题吗?我试图在网上搜索,但似乎找不到答案。
回答by Anthony Chu
VB.NET syntax to access an indexer should be with parentheses...
访问索引器的 VB.NET 语法应该带括号...
If ds.Tables(0).Rows.Count > 0 Then
回答by Madhawas
Your error is you have used "[]" in VB.net instead of "()"
您的错误是您在 VB.net 中使用了“[]”而不是“()”
Your code should be corrected as
您的代码应更正为
ds.Tables(0).Rows.Count