Database Error: There is no row at position 0 Database Error: There is no row at position 0 asp.net asp.net

Database Error: There is no row at position 0


This is very simple ... it means that no results were returned from your query. You always have to code defensively and check to see if the Rows array has any items in it before trying to index into it. Something like:

if (dt.Rows.Count > 0)    soptype = dt.Rows[0]["SOPTYPE"].ToString();else    somethingWentWrong();


you might have data in the table but I think the connection closes after the first query. try opening the connection again. Also you have string concatenation in the first SQL query, which isn't a good practice. try using block instead of try.. catch, just for a better code. And as Joel suggested, use a check


for (int i = 0; i <= dt.rows.count; i++){    // do something till rows in DT}