Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
}



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.
Posted
Updated 23-Jul-17 9:42am

1 solution

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[^]
 
Share this answer
 
Comments
ameyad09 23-Jul-17 22:25pm    
I tried that .It says table Select_By_SNAME_BLOCKNO has count of 0 ,meaning its empty.But i have no idea what is wrong.When i execute Select_By_SNAME_BLOCKNO procedure it returns the values
Graeme_Grant 23-Jul-17 22:32pm    
If you set a breakpoint before the query is executed and step through and check the result after, you will be able to see why.
ameyad09 23-Jul-17 23:01pm    
I have found this error now : Some columns are showing
Cannot evaluate expression because the code of the current method is optimized error.What changes do i need?

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