Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have database drive menu in the master page and have two tables master menu (menuid,menuname and loctaion)and product table i have stored the menu id in product table. now i want to display the product Details in view products.aspx page by getting the menuid in query string
C#
private void BindGridData()
   {
       con.Open();

       int menuid = int.Parse(Request.QueryString["MenuId"]);
       //string menuid = Request["id"].ToString();
       string sql = "select pro.ProductID,pro.MenuId,pro.ProductName,pro.ProductDescription,pro.Price,pro.ProductImage from rsa_ProductItemTable As pro,rsa_mastermenu As me where me.MenuId=pro.MenuId='" + menuid + "'";
           SqlDataAdapter da = new SqlDataAdapter(sql, con);
           DataSet ds = new DataSet();
           da.Fill(ds);
           DataList1.DataSource = ds;
           DataList1.DataBind();
           con.Close();
       }

And the error is Value cannot be null.
Parameter name: String
Please Help Me with this
Posted
Updated 2-Dec-14 6:52am
v2

try below sql statement, I have change your SQL and also added parameter
C#
string sql = "select pro.ProductID,pro.MenuId,pro.ProductName,pro.ProductDescription,pro.Price,pro.ProductImage from rsa_ProductItemTable As pro join rsa_mastermenu As me on  me.MenuId=pro.MenuId where pro.MenuId =@MenuId"; 
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.AddWithValue("@MenuId",menuid); 
DataSet ds = new DataSet();
da.Fill(ds);
 
Share this answer
 
1. Problem in writing the query: print your query you will get the error. Are you able to run the query in sql.
2. Correct you query like:

select pro.ProductID,pro.MenuId,pro.ProductName,pro.ProductDescription,pro.Price,pro.ProductImage from rsa_ProductItemTable As pro join rsa_mastermenu As me on me.MenuId=pro.MenuId and pro.MenuId ='" + menuid + "'";
 
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