Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to slove this error

There is no row at position 0.

My code
LblCountryName.Text = dat.Rows[0][0].ToString();
Posted

Hi Dear,

Please make sure that your DataTable is not null.

Please use below condition for check
C#
If(dat != null && dat.Rows.Count>0)
{
     LblCountryName.Text = dat.Rows[0][0].ToString(); 
}
else
{
     LblCountryName.Text = "DataTable is null or Not Contain Any Row(s).";
}


Thanks
 
Share this answer
 
Comments
Hasiya 8-Jan-13 23:52pm    
it's working ..Tnx dear tnx a lot.
Mr. Mahesh Patel 8-Jan-13 23:58pm    
If this is helpful then accept this solution by clicking of accept button so other developers can take reference of this solution.
Thanks dear
Check below Condition
C#
if(dat!= null)
{ 
    LblCountryName.Text = dat.Rows[0][0].ToString();
}
 
Share this answer
 
it's working ..Tnx dear tnx a lot.
 
Share this answer
 
The other poster is correct. To add two things:

1 - the error means what it says. You should understand what that error means, or you should not be writing code.

2 - You should never access an object in an array without first checking if it exists.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900