在代码中按价格添加搜索. [英] Adding search by prices in the code.
问题描述
我已经显示了按产品名称进行的搜索,如下所示.我想在同一代码中添加按价格查询的搜索..如何在相同的价格范围内添加按价格进行搜索,即0到5000、5000到15000等查询..我可以为此使用OR命令..我在这里使用面向对象的方法吗..如何摆脱sql隐喻..在哪里将cmd.Parameter.Add放入代码中.
我已经通过使用如下所示的sql查询显示了产品
I have shown the search by Products name as below.. i want to add the search by price query in the same code.. how can i add search by prices i.e range 0 to 5000, 5000 to 15000 e.t.c in the same query.. can i use OR command for that.. and i am using the object oriented aapproach here.. how can i get rid from sql concetination.. where to put cmd.Parameter.Add in the code.
I have shown the products by by using like sql query as below
private void Search()
{
string query = "Select * from Products where ProductName Like '" + Request.QueryString["Name"] + "%'";
DataSet ds = obj.fillgrid(query);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
我在dbcon类中有一个fillgrid方法.
and i have a fillgrid method in dbcon class as.
public DataSet fillgrid(String query)
{
DataSet ds = null;
try
{
SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connectionString);
ds = new DataSet();
dataAdapter.Fill(ds, "*.mdb");
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
}
return ds;
}
推荐答案
这不是完美的解决方案,它将立即解决您的问题.
由于您使用的是gridview,并且希望进行过滤和排序,因此我认为此链接将帮助您显示您的要求:
Gridview帮助器 [ ^ ]
其次,避免使用 SQL注入 [ ^ ]使用 ^ ].
要将参数添加到SQL查询时,请使用 cmd.Parameter.Add .为了更好地理解,请在此处 [ ^ ]
祝你好运,
OI
This is not the perfect solution and it will solve your problem mediately.
Since you are using a gridview and you want filtering and sorting I think this link will help you display what you ask for:
Gridview helper[^]
Secondly for avoiding SQL injections[^] use Parameterized Queries[^].
When you want to add a parameter to your SQL query you use, cmd.Parameter.Add. For better understanding check the provided link here[^]
Good luck,
OI
这篇关于在代码中按价格添加搜索.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!