110,539
社区成员
发帖
与我相关
我的任务
分享
string str = "select * from Record where 1=1 ";
......
if (starttime.Value != "" && endtime.Value != "")
{
str += string.Format(" CreatTime > = CONVERT(varchar(20),CreatTime,120) like '" + starttime.Value + "%' 'and CompleteTime < = CONVERT(varchar(20),CompleteTime,120) like'" + endtime.Value + "%''");//这句语法有问题
}
if (DropDownList1.SelectedValue != "")
{
str += string.Format(" and UserID='" + DropDownList1.SelectedItem.Text + "'");
}
else if (starttime.Value != "")
{
str += string.Format(" and CONVERT(varchar(20),CreatTime,120) like '" + starttime.Value + "%'");
}
else if (endtime.Value != "")
{
str += string.Format(" and CONVERT(varchar(20),CompleteTime,120) like'" + endtime.Value + "%'");
}
else if (starttime.Value != "" && endtime.Value != "")
{
str += string.Format("and CreatTime >= '" + starttime.Value + "'and CompleteTime <= '" + endtime.Value + "%'");
}
前三个if执行都对 当执行第四个if的时候 断点之后 程序没有执行第四个if 执行的是第二个if +第三个if sql没问题了 逻辑出问题;额
and CreatTime > = CONVERT(varchar(20),CreatTime,120) like '" + starttime.Value + "%' and CompleteTime < = CONVERT(varchar(20),CompleteTime,120) like'" + endtime.Value + "%'
if (DropDownList1.SelectedValue != "")
{
str += string.Format(" and UserID='" + DropDownList1.SelectedItem.Text + "'");
}
//将ID独立开
if (starttime.Value != "" && endtime.Value == "")
{
str += string.Format(" and CONVERT(varchar(20),CreatTime,120) like '" + starttime.Value + "%'");
}
else if (endtime.Value != "" && starttime.Value==“”)
{
str += string.Format(" and CONVERT(varchar(20),CompleteTime,120) like'" + endtime.Value + "%'");
}
else if (starttime.Value != "" && endtime.Value != "")
{
str += string.Format("and CreatTime >= '" + starttime.Value + "'and CompleteTime <= '" + endtime.Value + "%'");
}
个人建议有DateTimePicker控件来设定查询时间,而不是TextBox,因为TextBox很难控制输入格式的。[/quote]
学习了 asp.net我用的是js那个插件 解决了 谢啦