select * from tel where tdate <= ' + dtkp1.Text.ToString() + "'and tdate >= '"+dtp2.Text.Tostring();

解决方案 »

  1.   

    string Ins = "select * from tel where tdate<='"+dtp1.Text.tostring()+"' and tdate>='"+dtp2.Text.tostring()+"'";注意'和"的用法
      

  2.   

    哥们还是不行!再帮我仔细看看哪不对!下面是我写的
    "select * from tel where tdate=<'+dtp1.Text.ToString()+ "'and tdate>= '"+dtp2.Text.ToString();
      

  3.   

    string Ins = "select * from tel where tdate<="+System.Convert.ToDateTime(dtp1.Text)+" and tdate>="+System.Convert.ToDateTime(dtp2);
    因为时时间比较,最好统一转换成时间格式来比较
      

  4.   

    我又试了string Ins = "select * from tel where tdate<='"+dtp1.Text.ToString()+"' and tdate>='"+dtp2.Text.ToString()+"'";还是不对!
    卡卡
      

  5.   

    如下:
    string Ins = "select * from tel where tdate<="+"'"+dtp1.Text.ToString()+"'"+" and tdate>= "+"'"+dtp2.Text.ToString()+"'";
      

  6.   

    string Ins = "select * from tel where tdate<="+System.Convert.ToDateTime(dtp1.Text)+" and tdate>="+System.Convert.ToDateTime(dtp2);
    总是报在’0‘附近有语法错误
      

  7.   

    首先要确定使用的是什么数据库,如Oracle和SQL Server、DB2不有同语法。
    oracle:
    string Ins = "select * from tel where tdate<=to_date("+"'"+dtp1.Value.ToString()+"')"+" and tdate>= to_date("+"'"+dtp2.Value.ToString()+"')";db2、sql server:
    string Ins = "select * from tel where tdate<="+"'"+dtp1.Value.ToString()+"'"+" and tdate>= "+"'"+dtp2.Value.ToString()+"'";如上。
      

  8.   

    我用的是SQLSERVER,楼上的高人,我用的你的语句不出错了,但是找不出数据!怪拉!
      

  9.   

    dtp1,dtp2我是用的datetimepicker的控件,不是textbox!请高人再帮我看看怎么改,现在用了liuspcn(青竹)的代码,不报错了,但在dataGrid里找不到满足条件的记录
      

  10.   

    db2、sql server:
    string Ins = "select * from tel where tdate<="+"\'"+dtp1.Value.ToString()+"\'"+" and tdate>= "+"\'"+dtp2.Value.ToString()+"\'";
    不好意思,忘加转意符了"\".
      

  11.   

    是用参数进行查询,如下:
    string Ins="select * from tel where tdate<=@Date1 and tdate>=@Date2";SqlDataAdapter da=new SqlDataAdapter(Ins,yourConn);
    da.SelectCommand.Parameters.Add("@Date1",dtp1.Value);
    da.SelectCommand.Parameters.Add("@Date2",dtp2.Value);//Querying 
      

  12.   

    string Ins = "select * from tel where tdate<="+"'"+dtp1.Value.ToString()+"'"+" and tdate>= "+"'"+dtp2.Value.ToString()+"'";
    语法是正确的,但有时SQL与win的日期转换成字符串时因为格式不一样,比较不出来,保险的做法:
    DateTime dt1=dtp1.Value;
    string date1=string.Format("{0}-{1}-{2}",dt1.Year,dt1.Month,dt1.Day);
    DateTime dt2=dtp2.Value;
    string date2=string.Format("{0}-{1}-{2}",dt2.Year,dt2.Month,dt2.Day);
    string Ins = "select * from tel where tdate<='"+dt1+"' and '"+dt2 + "'";