string qs="select * from mytable where RECTIME between '" + start.ToString() + "' and '" + end.ToString() + "'";

解决方案 »

  1.   

    string qs="select * from mytable where RECTIME between "+"'"+start+"'"+" and "+"'"+end+"'";
      

  2.   

    按楼上的写法也不妥啊!报错:类型不匹配啊. RECTIME 是日期/时间类型 怎么可以用string来匹配啊?
      

  3.   

    string qs="select * from mytable where RECTIME between "+"'"+start+"'"+" and "+"'"+end+"'";
      

  4.   

    对与access应该是
    string qs="select * from mytable where RECTIME between #"+start+"# and #"+end+" #";
    sql server可以
    string qs="select * from mytable where RECTIME between "+start+" and "+end+" ";
      

  5.   

    Access 数据库的Date格式字段值必须由一对 # 符号标识
      

  6.   

    lyrixliu:我按你的写法没有报错,可是查询的结果并没有和start和end 匹配
       (我用的是C#)
      

  7.   

    在Oracle 中最好先转换为字符,然后再
    string qs="select * from mytable where RECTIME between  '"+start+"' and "+"'"+end+"'";
      

  8.   

    start和end为时间类型。
    string qs="select * from mytable where RECTIME between  '"+start.ToShortDateString()+"' and "+"'"+end.ToShortDateString()+"'";
      

  9.   

    access:
    string qs="select * from mytable where RECTIME between #"+start+"# and #"+end+" #";oracle:
    string qs="select * from mytable where RECTIME between to_date("+start+",'yyyy-mm-dd hh24:mm:ss') and to_date("+end+", 'yyyy-mm-dd hh24:mm:ss')";
      

  10.   

    string qs="select * from mytable where RECTIME between '" + start.ToString(MM/dd/yyyy) + "' and '" + end.ToString("MM/dd/yyyy") + "'";