Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
if (!IsPostBack) {
			con.Open();
			cmd.Connection = con;

			for (j = 0; j <= Session.Keys.Count - 1; j++) {
				  a[j]=Session.Keys[j];

			}

I got the error below Line;
a[j]=Session.Keys[j];

Exception Details: System.IndexOutOfRangeException: There is no row at position 1.

Source Error:


Line 39: Label l = default(Label);
Line 40: l = (Label)v.FindControl("Label1");
Line 41: l.Text = dt.Rows[ctr]["Serial"] + ".";
Line 42: l = (Label)v.FindControl("Label2");
Line 43: dt.Rows[ctr]["question"]=l.Text ;


Source File: e:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\WebSites\Subbu\WebSite6\Default2.aspx.cs Line: 41

i got Error below line

l.Text = dt.Rows[ctr]["Serial"] + ".";
Posted
Updated 5-Nov-11 20:01pm
v3

The array a[] should be as big as the Session.Keys, check that first.
 
Share this answer
 
Comments
Amir Mahfoozi 6-Nov-11 2:05am    
+5 I Agree
Mehdi Gholam 6-Nov-11 2:10am    
Cheers
Resolution for First Error:

Have you defined a properly? I tried your code with below syntax and it runs without any Error.
C#
try
{
    string[] a = new string[]{};

    for (int j = 0; j <= Session.Keys.Count - 1; j++)
    {
        a[j] = Session.Keys[j];

    }
}
catch (Exception ex)
{
    string error = ex.Message;
}


Resolution for Second Error:

Debug your code and check value of dt, it should not be null. Also check what value you are getting from dt.Rows[ctr]["Serial"].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900