Sur*_*raj 6 c# asp.net exception
请帮我解决这个问题...我收到的错误是"0号位没有行","索引超出范围的例外是用户代码无法解决的"
以下是我的代码
protected void Page_Load(object sender, EventArgs e)
{
    MTMSService obj = new MTMSService();
    DBAccess db = new DBAccess();
    {
        MTMSDTO objc = new MTMSDTO();
        {
            objc.TaskID = Convert.ToInt32(Session["TaskID"]);
            DataSet rep = obj.GetReports(objc);
            DataView Rprts = new DataView();
            Rprts.Table = rep.Tables[0];
            LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString();
            LblTaskName.Text = rep.Tables[1].Rows[0]["TaskName"].ToString();
            LblDueDate.Text = rep.Tables[2].Rows[0]["DueDate"].ToString();
            LblDescription.Text = rep.Tables[3].Rows[0]["Description"].ToString();
            LblAssignBy.Text = rep.Tables[4].Rows[0]["AssignBy"].ToString();
            LblStatus.Text = rep.Tables[5].Rows[0]["Status"].ToString();
            LblPercentageComplete.Text = 
                    rep.Tables[6].Rows[0]["PercentageComplete"].ToString();
            LblTaskName.Visible = true;
            LblAssignBy.Visible = true;
            LblDescription.Visible = true;
            LblDueDate.Visible = true;
            LblStatus.Visible = true;
            LblPercentageComplete.Visible = true;
            LblAssignTo.Visible = false;
        }
    }
}
Kja*_*tan 10
你没有检查你的表是否有任何内容.消息很明确 - 位置0没有行.它可能被抛出这一行,或者跟随它:
LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString();
在尝试从中获取数据之前,应检查是否存在行.类似的东西(在使用之前验证语法 - 这根本没有测试过):
var table = rep.Tables[0];
if (table.Rows.Count > 0){
    // Fetch the data... 
}
else
{
    // Handle missing data in an appropriate way...
}
| 归档时间: | 
 | 
| 查看次数: | 41469 次 | 
| 最近记录: |