VB.Net检查DataSet是否有行

时间:2014-02-26 06:33:24

标签: vb.net ms-access

 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

嗨,我正在尝试检查数据集是否有行。但是它给了我“ds.Tables [0] .Rows.Count> 0”的错误。我的代码有什么问题吗?我试图在网上搜索,但我似乎无法找到答案。

2 个答案:

答案 0 :(得分:8)

访问索引器的VB.NET语法应该带括号......

If ds.Tables(0).Rows.Count > 0 Then

答案 1 :(得分:1)

您的错误是您使用过" []"在VB.net而不是"()"

您的代码应更正为

ds.Tables(0).Rows.Count