Resign Designs

Resign Designs

  • NA
  • 31
  • 29.9k

How to get rid of out of range error?

May 5 2015 5:57 AM
Hi,
 
I have this code at page load to and it loads some data from db to form.
 
try
{
connection.Open();
adapter.SelectCommand = new SqlCommand("select * from mydb order by LangStaticID ASC", connection);
adapter.Fill(ds);
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
PageTitle.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
MetaTitle.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString(); 
}

when there are no results it gives me this error

 
How can I handle this error?

tried with this but no luck

if (ds.Tables[0].Rows.Count == 0)
{
//
}
 
Thanks
 

Answers (6)