从数据库检索值的代码 [英] code for retrive value from db
本文介绍了从数据库检索值的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以编写以下代码:
在此代码中无法从db获取价格值.如何从db获取价格值.
Can Anyone crt following code:
in this code can''t get the price value from db.how can i get the value from db.
price = ''" + price_range+ "'' it get only string as below Rs.500/- instead of this how can get values of less than 500 from database.
错误编码:
Error Coding:
protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
{
price_range = BulletedList3.Items[e.Index].Value;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
switch (price_range)
{
case "Below Rs.500/-":
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price = ''" + price_range+ "'' and status=''A'' and type=''retail'' ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
break;
case "Rs.500/- to Rs.1000/-":
SqlCommand cmd1 = new SqlCommand("select pro_img,pro_name,price from product where price = ''" + price_range + "'' and status=''A'' and type=''retail'' ", con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
DataList1.DataSource = ds1;
DataList1.DataBind();
con.Close();
break;
case "Rs.1000/- To Rs.2000/-":
SqlCommand cmd2 = new SqlCommand("select pro_img,pro_name,price from product where price = ''" + price_range + "'' and status=''A'' and type=''retail'' ", con);
SqlDataAdapter da2= new SqlDataAdapter(cmd2);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
DataList1.DataSource = ds2;
DataList1.DataBind();
con.Close();
break;
default:
break;
}
}
推荐答案
对于此范围标准,您应在之间使用
For this range criteria you should use
between and
运算符.
例如
operator in SQL statement.
For example
Select * from table where price between 500 and 1000
问候
酋长
Regards
Sheik
这篇关于从数据库检索值的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文