如何在asp.net的数据库驱动菜单中传递查询字符串 [英] How to pass query string in Database driven menu in asp.net
本文介绍了如何在asp.net的数据库驱动菜单中传递查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在母版页中有数据库驱动器菜单,并有两个表主菜单(menuid,menuname和loctaion)和产品表我已将产品表存储在产品表中。现在我想在查看products.aspx页面中显示产品详细信息,方法是在查询字符串中获取menuid
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
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
推荐答案
尝试下面的sql语句,我已经更改了你的SQL并添加了参数
try below sql statement, I have change your SQL and also added parameter
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);
1。编写查询时出现问题:打印查询会出现错误。你能在sql中运行查询。
2.纠正你的查询,如:
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 +';
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 + "'";
这篇关于如何在asp.net的数据库驱动菜单中传递查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文