Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
{
            string keyword = Request.QueryString["Mailid"];
            DataSet oDS = new DataSet();
            oDS = SearchHelper.getResultByKeywords(keyword);
            string itempic = oDS.Tables[0].Rows[0]["SGL_IMG"].ToString();
            //string url = Convert.ToString(Session["url"]);
            string img = "http://content.oppictures.com/Master_Images/Master_Variants/Variant_400/" +  itempic;

        }
Posted
Comments
Member 10184990 16-Aug-13 5:32am    
error comes in this line (there is no row at oDS.Tables[0].Rows[0]) string itempic = oDS.Tables[0].Rows[0]["SGL_IMG"].ToString();
CodeBlack 16-Aug-13 8:17am    
as error says : "there is no row at oDS.Tables[0].Rows[0]"
SearchHelper.getResultByKeywords(keyword); doesnt return any value. and put if condition for the null check and check whether there is any data in the table or not.

the record with the keyword does not exists in database its returning null value. when you are trying to assign the value to a string its throwing exception. So before assigning the value check whether any table exists in the result.
 
Share this answer
 
Make sure your query is returning a value, otherwise this code will throw an exception.

A simple test is:

C#
if (oDS.Tables.Count > 0 && oDS.Tables[0].Rows.Count > 0)
{
     // data returned, so go create the image URL
}
else
{
     // no data returned, so handle the error here   
}
 
Share this answer
 

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