By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Index 0 Error

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.