In my if statement below I need to check if in the first tables first row/column contains a string but I get an exception if the table has no rows.
the exception is:
“System.IndexOutOfRangeException = {“There is no row at position 0.”}”
Code snippet:
'if the table has no rows then an exception happens here
If myDataSet.Tables(0).Rows(0)(0).ToString <> "MyMessage" then
'do this - redirect
Else
myDataSet.Tables(0).Rows(0)(0) = "no message"
End If
Can you help please?
It throws an exception because you’re assuming a row exists with the following statement
If myDataSet.Tables(0).Rows(0)(0)You should check that you have a row first by doing
If myDataSet.Tables(0).Rows.Count > 0