日期:2014-05-18  浏览次数:20830 次

data table .select 筛选时间的问题
DataRow[] rows = dtNeed.Select("collect_time between " + time.AddHours(-2).ToString() + " and " + time.AddHours(1).ToString() + "");

------解决方案--------------------
DataRow[] rows = dtNeed.Select("collect_time between '" + time.AddHours(-2).ToString("yyyy-MM-dd HH:mm:ss") + "' and '" + time.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); 
再不行就
DataRow[] rows = dtNeed.Select("collect_time >= '" + time.AddHours(-2).ToString("yyyy-MM-dd HH:mm:ss") + "' and collect_time <= '" + time.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "'");
------解决方案--------------------
这样试试
C# code

            DateTime time = DateTime.Now;
            string sqlstr = "collect_time between '" + time.AddHours(-2).ToString() + "' and '" + time.AddHours(1).ToString() + "'";
            DataTable dtNeed = new DataTable();
            DataRow[] rows = dtNeed.Select(sqlstr);