帮助这个数组解决 [英] Help for this array solve

查看:77
本文介绍了帮助这个数组解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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";
       }





我的尝试:



请帮助所有类型使用i数组,简单字符串但是所有行都不插入只有第一行插入后面的错误



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

推荐答案

你的方法是否返回一个 DataTable 对象?

如果不是,你的整个逻辑可能会失败。



如果是,您还没有对数据表确实包含行的检查进行任何检查。因此,当存在空数据表时,以下代码行将引发错误。

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.
pp[i] += con.QueryEx().Rows[i][j].ToString();
//will be evaluated to following
pp[0] += con.QueryEx().Rows[0][0].ToString();





它传递了previos步骤,因为行和列计数为0但会在在线上。



尝试进行一些验证,例如:



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-

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 :)


这篇关于帮助这个数组解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆