I have a function that search for a keyword and then return DataTable. I want to check if there rows inside because sometimes there's no query found.
'which one shoud I use ?
If dtDataTable Is Nothing Then
'some code
lbl_count.Text = "Found 0 result"
End If
If dtDataTable.Rows.Count > 0 Then
'some code
lbl_count.Text = "Found " & dtDataTable.Rows.Count.ToString & " results"
End If
Thanks.
If the count is greater than zero then the row already exists in the Datatable else the datarow is not present in the datatable.
Hi @Ravi, to check whether a string is present in a data table or not, you need to use ReadRange activity to read your excel file and store its output in a data table. Then use ForEachRow activity to read each row of the data table and use If activity to put the condition for matching the string.
How about:
If dtDataTable IsNot Nothing AndAlso dtDataTable.Rows.Count > 0 Then
'some code
lbl_count.Text = "Found " & dtDataTable.Rows.Count.ToString & " results"
Else
'some code
lbl_count.Text = "Found 0 result"
End If
If you're using VB 9.0 (VS 2008) you can simply this with the following
lbl_count.Text = String.Format("Found {0} result(s)", if(dbDataTable, dbDataTable.Rows.Count,0))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With