You can check here a few things with such things. I usually check that Dataset not null, and then make sure it has at least one table and one row. If he has all these things, then double-check that the value you are looking for is not null and is an actual integer. Here is an example (VB.NET because I am familiar):
Dim IsLocationCounter As Integer If (Not pds Is Nothing AndAlso pds.Tables.Count > 0 AndAlso pds.Tables[0].Rows.Count > 0) Then If (pds.Tables[0].Columns[0].ColumnName[1] <> DBValue.Null) Then If ( Not Integer.TryParse(pds.Tables[0].Columns[0].ColumnName[1].ToString(), IsLocationcounter) ) Then Throw New Exception ("Do some error handling here because there is no int coming back in your dataset") End If End If End If
As a note for the example that you have in your question, you cannot use this IsLocationCount variable outside this If statement if you declare it inside an If statement. If you need it outside the If statement, you must declare it outside of the If statement.
source share