Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Server Error in '/wwwroot' Application.

There is no row at position 1.

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: There is no row at position 1.

Source Error: 


Line 135:            for (int j = 0; j < b; j++)
Line 136:            {
Line 137:                pp[i] += con.QueryEx().Rows[i][j].ToString();
Line 138:                if (j == b - 1)
Line 139:                {

Source File: c:\inetpub\wwwroot\Gujarati_sms.aspx.cs    Line: 137 

Stack Trace: 




for this code
run


C#
int p = con.QueryEx().Rows.Count;
       int b = con.QueryEx().Columns.Count;
       for (int i = 0; i < p; i++)
       {
           for (int j = 0; j < b; j++)
           {
               pp[i] += con.QueryEx().Rows[i][j].ToString();
               if (j == b - 1)
               {
                  // TextBox3.Text += pp[i];
                  con.SqlQuery("insert into Sms_Genrate(Message) values ('" + pp[i] + "')");
                   con.NonQueryEx();
               }
           }
           TextBox3.Text += tt + "\r\n";
       }


What I have tried:

please help all type use i array , simple string but all rows not insert only first rows are insert after above error
Posted
Updated 1-Aug-16 22:00pm

1 solution

Is your method returning a DataTable object?
If no, your whole logic may got fail.

If yes, you haven't put any check on wheather that datatable really contains a row or not. So, following line of code will raise error when there is an empty datatable.
C#
pp[i] += con.QueryEx().Rows[i][j].ToString();
//will be evaluated to following
pp[0] += con.QueryEx().Rows[0][0].ToString();


It pass previos steps as the rows and columns count is 0 but will throw error in the above line.

Try putting some validation like-
C#
int p = con.QueryEx().Rows.Count;
int b = con.QueryEx().Columns.Count;
if(p>0)
{
   for (int i = 0; i < p; i++)
   {
      //rest of the logic here
   }
} 


Hope, it helps :)
 
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