Quote:
IndexOutOfRangeException was unhandled by user code
That means the index you are trying to access is not available.
if (ds.Tables[0].Rows.Count > 0)
Here if the
DataSet
is empty, the
Tables[0]
would throw this exception.
So, you need to first check the query and what it fetches from Database. Also use Parameterized query instead of inline queries, as it is vulnerable to SQL Injection.