c#里的简单SQL查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/09 06:14:10
想做一个查询,满足3个条件。1、两个datepicktime的控件,选择个时间段(STIME)。2、柜号(COUNTER)。3、温度(STEMP)大于100度。
晕。。低级错误,自己查出来了!
select * from ttest where convert(char(10),sTime,120) between '" + dateTimePicker3.Value.ToString("yyyy-MM-dd") + "' and '" + dateTimePicker4.Value.ToString("yyyy-MM-dd") + "'and sCounter='"+textBox8.Text+"' and sTemp>'"+textBox9.Text+"'
不过还是谢谢你,还有不是=iTemp 是>iTemp哦

select * from YourTable
where
stime between @dtTime1 and @dtTime2
and counter = @iCounter
and stemp = @iTemp

在此,stime, counter, stemp都是你表中的字段,@开头的是查询参数,注意定义其数据类型,把C#控件中的值传给SqlCommand对象即可。

赫赫
这种低级错误俺也犯过<*-_-*>