先上代码:
【c#】
string sql = "SELECT 'stuName','stuId','stuTime' FORM Student (WHERE stuTime BETWEEN \'" + startTime + "\' AND \'" + endTime + "\')";startTime是string类型的开始时间格式为:2013/3/14
endTime是结束时间我在vs2010中调试了很多遍就是不对,请各位大大帮忙解决!万分感谢!  

解决方案 »

  1.   

    access 日期比较两边不是用单引号,要用#
    string sql = "SELECT 'stuName','stuId','stuTime' FORM Student (WHERE stuTime BETWEEN #" + startTime + "# AND #" + endTime + "#)";
      

  2.   

    用Pamameters:
    DateTime theDate = new DateTime(2012,10,16);
    var cmd = new OleDbCommand();
    cmd.CommandText = "INSERT INTO sometable (column) VALUES (@p_bar)";
    cmd.Parameters.Add ("@p_bar", OleDbType.DateTime).Value = theDate;
    代码来自:
    http://stackoverflow.com/questions/12922292/insert-datetime-into-access
      

  3.   

    谢谢您的回答!
    可是......
    语法错误 (操作符丢失) 在查询表达式 ''stuTime' FORM Student (WHERE stuTime BETWEEN #2013/3/14# AND #2013/3/14#)' 中。
    该怎么解决啊 
      

  4.   

    SELECT 'stuName','stuId','stuTime' FORM Student WHERE stuTime BETWEEN CONVERT(varchar(10),"+startTime+", 23) AND CONVERT(varchar(10), "+endTime+", 23)";自己在调试下吧,吧时间类型转换下,最好使用参数。
      

  5.   

    WHERE  datediff('d','"+startime+"',stuTime)>0 and datediff('d','"+endtime+"',stuTime)<0