string queryselect = "select * from jt where 1=1 ";
if (cb1.Checked)
{
queryselect += " and model = '" + cbbcategory.Text + " '";
}
if (cb2.Checked)
{
queryselect += " and modelnumber" + " like '%" + txtMN.Text + "%'";
}
if (cb3.Checked)
{
queryselect += " and problemdescribe" + " like '%" + cbbQC.Text + "%'";
}
if (cb4.Checked)
{
queryselect += " and author" + " like '%" + txtAuthor.Text + "%'";
}
//if (cb5.Checked)
//{
//queryselect += " and data" + " like '%" + txtTime.Text + "%'";
//}
if (cb5.Checked && cb6.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect = "select * from jt where data >= '" + ss + "' and '" + ee + "'";
}
16 个解决方案
#1
if(cb5.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data>="+ss;
}
if(cb6.Checked)
{
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data<="+ee;
}
#2
queryselect = "select * from jt where data between '" + ss + "' and '" + ee + "'";
??
#3
按这个方法还是报错,查询不出来。。。
#4
报错信息是“语法错误 (操作符丢失) 在查询表达式 '1=1 data >=2013-06-01 00:00:00 data<=2013-06-10 00:00:00' 中。“
#5
用1楼和3楼的方法应该都可以吧
if (cb5.Checked && cb6.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect = "select * from jt where data >= '" + ss + "' and data<='" + ee + "'";
}
if(cb5.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data>="+ss;
}
if(cb6.Checked)
{
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data<="+ee;
}
#2
queryselect = "select * from jt where data between '" + ss + "' and '" + ee + "'";
??
#3
if(cb5.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data>="+ss;
}
if(cb6.Checked)
{
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect+="data<="+ee;
}
按这个方法还是报错,查询不出来。。。
#4
报错信息是“语法错误 (操作符丢失) 在查询表达式 '1=1 data >=2013-06-01 00:00:00 data<=2013-06-10 00:00:00' 中。“
#5
用1楼和3楼的方法应该都可以吧
if (cb5.Checked && cb6.Checked)
{
string ss = startTime.Value.ToString("yyyy-MM-dd 00:00:00");
string ee = endTime.Value.ToString("yyyy-MM-dd 00:00:00");
queryselect = "select * from jt where data >= '" + ss + "' and data<='" + ee + "'";
}