Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net Checking if DataSet has rows or not

 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.

like image 451
user3148632 Avatar asked Feb 26 '14 06:02

user3148632


2 Answers

VB.NET syntax to access an indexer should be with parentheses...

If ds.Tables(0).Rows.Count > 0 Then
like image 191
Anthony Chu Avatar answered Oct 01 '22 09:10

Anthony Chu


Your error is you have used "[]" in VB.net instead of "()"

Your code should be corrected as

ds.Tables(0).Rows.Count
like image 43
Madhawas Avatar answered Oct 01 '22 09:10

Madhawas