Indexoutofrangeexception:位置0没有行 [英] Indexoutofrangeexception :there is no row at position 0

查看:128
本文介绍了Indexoutofrangeexception:位置0没有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,所以我在网上经历了一些项目。我无法运行这个项目



我收到以下错误点击登录按钮:



位置0没有行

具体来自Image3.ImageUrl = HDT.Rows [0] [ 图像]的ToString();行。



I am very new to C#,so i was going through some projects online.I wasnt able to run this project

I am getting the following error when I click on the login button:

There is no row at position 0
Specifically from the Image3.ImageUrl = HDT.Rows[0]["image"].ToString(); line.

DS_HOUSE.HOUSE_SELECTDataTable HDT = new DS_HOUSE.HOUSE_SELECTDataTable();
DS_HOUSETableAdapters.HOUSE_SELECTTableAdapter HAdapter = new 
DS_HOUSETableAdapters.HOUSE_SELECTTableAdapter();

 protected void Page_Load(object sender, EventArgs e)
{
   UDT = UAdapter.Select_By_UID(Convert.ToInt32(Session["uid"].ToString()));
   HDT = HAdapter.Select_By_SNAME_BLOCKNO(UDT.Rows[0]["societyname"].ToString(), Convert.ToInt32(UDT.Rows[0]["Houseid"].ToString()));
   Image3.ImageUrl = HDT.Rows[0]["image"].ToString();
   lblsname.Text = HDT.Rows[0]["sname"].ToString();
   lblbno.Text = HDT.Rows[0]["blockno"].ToString();
   lbltype.Text = HDT.Rows[0]["type"].ToString();
   ViewState["HID"] = HDT.Rows[0]["HID"].ToString();
}







我附上完整的项目源代码和数据库备份文件。请发布。尝试在你的系统上运行,因为我没有关于该项目的详细知识,作为初学者



[带有数据库备份文件的项目源代码附于此处]



我尝试了什么:



我尝试将代码放入if块中








I am attaching the full project source code and database backup file .Please try running on your system as i dont have detailed knowledge about the project, being a beginner

[Project Source Code with Database Backup File is attached here]

What I have tried:

I tried putting the code within if block with


 protected void Page_Load(object sender, EventArgs e)
   {
         
        lblsell.Text = "";
        UDT = UAdapter.Select_By_UID(Convert.ToInt32(Session["uid"].ToString()));
        HDT = HAdapter.Select_By_SNAME_BLOCKNO(UDT.Rows[0]["societyname"].ToString(), Convert.ToInt32(UDT.Rows[0]["Houseid"].ToString()));
if (HDT.Rows.Count > 0)
    {
            Image3.ImageUrl = HDT.Rows[0]["image"].ToString();
            lblsname.Text = HDT.Rows[0]["sname"].ToString();
            lblbno.Text = HDT.Rows[0]["blockno"].ToString();
            lbltype.Text = HDT.Rows[0]["type"].ToString();
            ViewState["HID"] = HDT.Rows[0]["HID"].ToString();
        
    }
}





我能够登录但是我无法从中检索细节社会表。



I was able to login however i was unable to retrieve details from the Society table.

推荐答案

错误信息非常明确。现在是时候使用调试器来查看没有返回行的原因并添加代码来处理没有返回数据的情况。



如果你不熟悉关于如何调试项目,那么这个视频是一个很好的介绍如何:使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]
The error message is very explicit. Now it is time to use the debugger to see why no rows are being returned and add code to handle those cases where no data is returned.

If you are not familiar with how to debug a project, then this video is a great introduction on how to:Basic Debugging with Visual Studio 2010 - YouTube[^]


这篇关于Indexoutofrangeexception:位置0没有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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