SqlDataAdapter my = new SqlDataAdapter("SELECT * FROM tblFinish WHERE RecordTime<'Convert.ToDateTime(TextBox4.Text)' AND RecordTime>='Convert.ToDateTime(TextBox3.Text)'", sqlconn);
这句话出错,该怎么改呢??赐教!!

解决方案 »

  1.   

    建议把Convert.ToDateTime(TextBox4.Text) 值副给一个变量 如 times!
    然后在sql语句中用@times表示他!试试看吧!
      

  2.   

    SqlDataAdapter my = new SqlDataAdapter("SELECT * FROM tblFinish WHERE RecordTime<'" + TextBox4.Text + "' AND RecordTime>='" + TextBox3.Text + "'", sqlconn);
      

  3.   

    sql2000中有现成的例子具体说就太多了!
      

  4.   

    如果TextBox内容为空或不是有效的日期格式就会报错,可以先判断!
      

  5.   

    SqlDataAdapter my = new SqlDataAdapter("SELECT * FROM tblFinish WHERE RecordTime<'" + TextBox4.Text + "' AND RecordTime>='" + TextBox3.Text + "'", sqlconn);这句如果想把TextBox4.Text的时间自动加59:59:59怎么改呢SqlDataAdapter my = new SqlDataAdapter("SELECT * FROM tblFinish WHERE RecordTime<'" + TextBox4.Text +59:59:59 "' AND RecordTime>='" + TextBox3.Text + "'", sqlconn);这样好像不行也
      

  6.   

    如下修改:
    SqlDataAdapter my = new SqlDataAdapter("SELECT * FROM tblFinish WHERE RecordTime<'"+TextBox4.Text.Trim()+"' AND RecordTime>='"+TextBox3.Text.Trim()+"';", sqlconn);t-sql中的日期表示是看作字符串的
    TextBox4.Text的日期格式:2005-2-26
    只要TextBox4.Text日期格式写正确,这个语句一定能执行