Index 0 Error

G

Guest

When I run the following code

public DataView CreateEquipmentDataSource(

string equipConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString() + ""
string equipSelect = "Select Description from Equipment where"
" Eqnum = " + "'" + equipLabel.Text + "'"

oda1 = new OleDbDataAdapter(equipSelect, equipConnect)
DataSet ds1 = new DataSet()

oda1.Fill(ds1, "Equip")
DataView Equip = ds1.Tables["Equip"].DefaultView
return Equip


public void FillEquipment(

DataView eq = CreateEquipmentDataSource()
equipDescLabel.Text = eq[0].Row["Description"].ToString()

I get the following error

Server Error in '/5YearPlan' Application.

Index 0 is not non-negative and below total rows count.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index 0 is not non-negative and below total rows count

Source Error:

Line 302:
Line 303: DataView eq = CreateEquipmentDataSource()
Line 304: equipDescLabel.Text = eq[0].Row["Description"].ToString()
Line 305:
Line 306

Source File: c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs Line: 304

Stack Trace:

[IndexOutOfRangeException: Index 0 is not non-negative and below total rows count.
System.Data.DataView.GetElement(Int32 index) +4
System.Data.DataView.get_Item(Int32 recordIndex) +
_5YearPlan.workorderForm.FillEquipment() in c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs:30
_5YearPlan.workorderForm.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs:16
System.Web.UI.Control.OnLoad(EventArgs e) +6
System.Web.UI.Control.LoadRecursive() +3
System.Web.UI.Page.ProcessRequestMain() +73


Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.57

Do you have any idea what is causing this

Thanks

Dav
 
N

Nick Malik

yes... there are no rows in the database that match your criteria.
Therefore, your dataset has no resulting rows.

Check the rowcount before you try to assign a value from the first row.

--- Nick

Dave Bailey said:
When I run the following code:


public DataView CreateEquipmentDataSource()
{
string equipConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString() + "";
string equipSelect = "Select Description from Equipment where" +
" Eqnum = " + "'" + equipLabel.Text + "'";

oda1 = new OleDbDataAdapter(equipSelect, equipConnect);
DataSet ds1 = new DataSet();

oda1.Fill(ds1, "Equip");
DataView Equip = ds1.Tables["Equip"].DefaultView;
return Equip;
}

public void FillEquipment()
{
DataView eq = CreateEquipmentDataSource();
equipDescLabel.Text = eq[0].Row["Description"].ToString();
}
I get the following error.

Server Error in '/5YearPlan' Application.

Index 0 is not non-negative and below total rows count.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index 0 is not
non-negative and below total rows count.
Source Error:

Line 302: {
Line 303: DataView eq = CreateEquipmentDataSource();
Line 304: equipDescLabel.Text = eq[0].Row["Description"].ToString();
Line 305: }
Line 306:

Source File: c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs Line: 304

Stack Trace:

[IndexOutOfRangeException: Index 0 is not non-negative and below total rows count.]
System.Data.DataView.GetElement(Int32 index) +43
System.Data.DataView.get_Item(Int32 recordIndex) +4
_5YearPlan.workorderForm.FillEquipment() in c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs:304
_5YearPlan.workorderForm.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\5yearplan\workorderform.aspx.cs:164
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731


Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Do you have any idea what is causing this:


Thanks,

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top