Error: There is no row at position 0

liunx

Guest
I am creating a web page where the user can edit information in the datagrid but I keep getting this error:Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

Source Error:


Line 40: AdNumSent = Request.QueryString("rfqID")
Line 41: GetAd(AdNumSent)
Line 42: Row = faqlog.Tables("faqlog").Rows(0)
Line 43: idtext.Text = Row.Item("rfqID")
Line 44: rfqQuestionText.Text = Row.Item("rfqQuestion")

Thanks loadsFor anyone who's interested it worls now, this is what I changed the code to: (an If statement was added) :)

If faqlog.Tables("faqlog").Rows.Count > 0 Then
Row = faqlog.Tables("faqlog").Rows(0)
...
End IFHI, i am currently working on a UI which ultilises xml strings from a web service. However, when i run the program, there is an error. It says this

System.IndexOutOfRangeException was unhandled by user code
Message="There is no row at position 0."
Source="System.Data"
StackTrace:
at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
at System.Data.RBTree`1.get_Item(Int32 index)
at System.Data.DataRowCollection.get_Item(Int32 index)
at a.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\OrdersWebApplication\a.aspx.cs:line 25
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


This is my code

public partial class a : System.Web.UI.Page
{
string Product;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{

Product = Request.QueryString["ProductName"];

if (!IsPostBack)
{
OS1.Service Web1 = new OS1.Service();
ds = Web1.ShowProduct(Product);
ProductID.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
ProductName.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
Price.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
Quantity.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();

Web1.Dispose();

}

}
}



Do you know of any way i n which i can solve this? Thank you in advance.The error isn't in that code, its in Web1.ShowProduct(). Web1.SHowProduct is probably returning an empty dataset. Try, just for the sake of avoiding an error, doing what the previous poster did and checking the dataset length before accessing a value from it, this should atleast not make it return an error message but it obviously isn't going to show what you want.Hi. i tried making some modifications, and this is what i found. No value is being provided for the field UID in thge following coding

public partial class Delete : System.Web.UI.Page
{
string UID;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
UID = Request.QueryString["UserName"];

if (!IsPostBack)
{
OS1.Service Web1 = new OS1.Service();
ds = Web1.EditUser(UID);

// UserId.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
UserName.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
CompanyName.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
Description.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
Products.Text = ds.Tables[0].Rows[0].ItemArray[4].ToString();
ContactPerson.Text = ds.Tables[0].Rows[0].ItemArray[5].ToString();
Telephone.Text = ds.Tables[0].Rows[0].ItemArray[6].ToString();
Fax.Text = ds.Tables[0].Rows[0].ItemArray[7].ToString();
Email.Text = ds.Tables[0].Rows[0].ItemArray[8].ToString();
Website.Text = ds.Tables[0].Rows[0].ItemArray[9].ToString();
FileName.Text = ds.Tables[0].Rows[0].ItemArray[10].ToString();
Designation.Text = ds.Tables[0].Rows[0].ItemArray[12].ToString();

Web1.Dispose();


}


The value UID is supposed to have come from a datagrid, in which userName can be clicked on. Upon clickng userName, user should be directed to page where all his particulars will be displayed. However, it seems that when my program is being played, and when i click on the userName, it doesnt redirect me to the next page ("Delete.aspx") Tgis is the code for the main page ("Default.aspx"). Thank you for your help





public partial class _Default : System.Web.UI.Page
{
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
OS1.Service Web1 = new OS1.Service();

ds = Web1.EditUser("*");

DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataSource = ds;

DataGrid1.DataBind();

Web1.Dispose();
}
}

protected void InitializeComponent()
{
this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);

this.DataGrid1.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
}

protected void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
OS1.Service Web1 = new OS1.Service();

ds = Web1.EditUser("*");
DataGrid1.CurrentPageIndex = e.NewPageIndex;

DataGrid1.DataSource = ds;
DataGrid1.DataBind();
Web1.Dispose();
}

protected void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "UserName")
{
Response.Redirect("Delete.aspx?UserName=" + e.Item.Cells[0].Text);
}
}Why not just use a hyperlink column in the datagrid?
 
Back
Top