There is no row at position 0 error

Posted by Adanjali under ASP.NET on 4/21/2015 | Points: 10 | Views : 583 | Status : [Member] | Replies : 1
protected void Select_Associate_Details(string profileId)
{
nvclin["ProfileId"] = profileId;
DataTable dt = objMaster.Select_Member_Associate_Details(nvclin);
if (dt.Rows.Count > 0)
{
if (dt.Rows.Count > 2)
{
lblass1.Text = dt.Rows[0]["AssociateName"].ToString();
lblasscompany1.Text = dt.Rows[0]["AssociateCompany"].ToString();
lblassMobile1.Text = dt.Rows[0]["AssociateMobile"].ToString();
lblassEmail1.Text = dt.Rows[0]["AssociateEmail"].ToString();
if (dt.Rows[0]["AssociatePhoto"].ToString() != "")
{
ltrAssocaiateImage1.Text = "";
ltrAssocaiateImage1.Text = "<img src=\"" + ConfigurationManager.AppSettings["WebURL"].ToString() + dt.Rows[0]["AssociatePhoto"].ToString() + "\" alt=\"ProfilePhoto\" />";
}

hdfAssociate1.Value = dt.Rows[0]["AssociateID"].ToString();
nvclin["AssociateID"] = hdfAssociate1.Value;
DataTable dtExp1 = objMaster.Select_Associate_Expertise_Details(nvclin);
string strAssexpertise1 = "";
if (dtExp1.Rows.Count > 0)
{
foreach (DataRow row in dtExp1.Rows)
{
strAssexpertise1 += row["Expertise"].ToString() + " / ";
}
strAssexpertise1 = strAssexpertise1.Remove(strAssexpertise1.Length - 2);
}
else
{
strAssexpertise1 = "Not Available";
}
lblassExpertise1.Text = strAssexpertise1;


lblass2.Text = dt.Rows[1]["AssociateName"].ToString();
lblasscompany2.Text = dt.Rows[1]["AssociateCompany"].ToString();
lblassMobile2.Text = dt.Rows[1]["AssociateMobile"].ToString();
lblassEmail2.Text = dt.Rows[1]["AssociateEmail"].ToString();
if (dt.Rows[0]["AssociatePhoto"].ToString() != "")
{
ltrAssocaiateImage2.Text = "";
ltrAssocaiateImage2.Text = "<img src=\"" + ConfigurationManager.AppSettings["WebURL"].ToString() + dt.Rows[1]["AssociatePhoto"].ToString() + "\" alt=\"ProfilePhoto\"/>";
}
hdfAssociate2.Value = dt.Rows[1]["AssociateID"].ToString();
nvclin["AssociateID"] = hdfAssociate2.Value;
DataTable dtExp2 = objMaster.Select_Associate_Expertise_Details(nvclin);
string strAssexpertise2 = "";


}




Responses

Posted by: Bandi on: 4/21/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
I think you are missing or have mismatched closing bracket } symbol...

cross verify to make sure that if (dt.Rows.Count > 0) { having close bracket and also what's the ELSE part of this IF condition...

http://stackoverflow.com/questions/18941334/there-is-no-row-at-position-0-what-should-i-do
http://forums.asp.net/t/1028324.aspx?Error+There+is+no+row+at+position+0
http://stackoverflow.com/questions/19710458/no-row-at-position-0-error-handing


it is always good to validate wether the dataset has data or is empty you can use something like this to cover all validations

 if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

{
//process data
}
else
{
// it is empty
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Adanjali, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response