在位置0没有行..为什么我得到这个错误任何人都请帮助我

问题描述:

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

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 0.



源错误:


Source Error:

Line 434:            System.Data.DataSet dt6 = new System.Data.DataSet();
Line 435:            da.Fill(dt6);
Line 436:            string amp5 = dt6.Tables[0].Rows[0][0].ToString();
Line 437:            string str6 = amp5.Replace("&", "&");
Line 438:            // ddlcomm.Text = str6;

显然,当行数为你需要在索引一行之前检查这种情况。



-SA
Apparently, it can happen when the number of rows is 0. You need to check for such cases before indexing a row.

—SA


例外情况将在第436行。



在操作这些变量之前检查表和行索引始终是一个好习惯。因为有时你不能保证它总是按预期返回值。

the exception will be at line 436.

its always a good practice to check the table and row index before you operate on those variables. because at times you cannot guarantee it always returns the values as expected.
if( dt6.Tables.Count >0 && dt6.Tables[0].Rows.Count > 0)
{  
 string amp5 = dt6.Tables[0].Rows[0][0].ToString();
}


实际上在这一行你得到了这个错误信息



Actually in this line you got this error message

string amp5 = dt6.Tables[0].Rows[0][0].ToString();





在Row [0]中,没有显示此错误的数据。

所以,在此之前你检查条件然后在这里写下这行代码如果条件。





In Row[0],there is no data that''s way this error showing.
So, before that you check condition and then wrote this lines of code inside the If condition.

if(dt6.Tables[0].Rows.Count>0)
{
    string amp5 = dt6.Tables[0].Rows[0][0].ToString();
}