asp.net C#时间段查询问题,如何获取时间
asp.net C#时间段查询问题,如何获取时间
代码如下
string sqlstr = "select * from eNewView";
string time1 = this.time1.Text.Trim();
string time2 = this.time2.Text.Trim();
if (time1 != "" && time2 != "")
{
if (wherestr.Trim() == "")
{
wherestr = "shijian >= '" + time1.Text.Trim() + "' AND shijian <= '" + time2.Text.Trim() + "'";
}
else
{
wherestr = wherestr + " AND shijian >= '" + time1.Text.Trim() + "' AND shijian <= '" + time2.Text.Trim() + "'";
}
}
主要是这部分代码,如何获取正确时间数据
'" + time1.Text.Trim() + "'
[解决办法]
if (this.time1.Text.Trim() != "" && this.time2.Text.Trim() != "")
{
if (wherestr.Trim() == "")
{
wherestr = "shijian >= '" + time1.Text.Trim() + "' AND shijian <= '" + time2.Text.Trim() + "'";
}
else
{
wherestr = wherestr + " AND shijian >= '" + time1.Text.Trim() + "' AND shijian <= '" + time2.Text.Trim() + "'";
}
}