Index error makes no sense

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I run the following code

public DataView CreateLocationDataSource()
{
string locationConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString() + "";
string locationSelect = "SelectDescription from Locations " +
" where Location = " + "'" + locationLabel.Text.ToUpper() + "'";

oda2 = new OleDbDataAdapter(locationSelect, locationConnect);
DataSet ds2 = new DataSet();

oda2.Fill(ds2, "Locate");
DataView Locate = ds2.Tables["Locate"].DefaultView;
return Locate;
}

public void FillLocation()
{
DataView loc = CreateLocationDataSource();
locDescLabel.Text = loc[0].Row["Description"].ToString();
}

I get the following error:

Index 0 is not non-negative and below total rows count.


Since I am using void why does this happen and how can I cahange my code to prevent it?

Thanks,

Dave
 
I am confused what does "i am using void' mean?

In any case, it seems like no rows are being returned.
 
Did you get back any rows? Asking for row 0 when there aren't any rows will
be a problem.
 
Back
Top