VB.Net Checking for rows or not in a DataSet

 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 am trying to check if a dataset has rows. But this gives me an error in "ds.Tables [0] .Rows.Count> 0". Is there something wrong with my code? I tried to search the net, but I can not find the answer.

+4
source share
2 answers

VB.NET syntax for accessing the indexer must be with parentheses ...

If ds.Tables(0).Rows.Count > 0 Then
+9
source

Your mistake is that you used "[]" in VB.net instead of "()"

Your code should be adjusted as

ds.Tables(0).Rows.Count
+1
source

Source: https://habr.com/ru/post/1528898/


All Articles