限制条件这样写 
"where time between '" + TextBox1.Text.tostring +"' and DateAdd(day,1,"+TextBox1.Text.tostring +")"

解决方案 »

  1.   

    制条件这样写 
    "where time between '" + TextBox1.Text.tostring +"' and DateAdd(day,1,"+TextBox1.Text.tostring +")"什么意思啊??还需要这样写吗??
      

  2.   

    1。
    在对一个数据库进行按天查询的时候,总是实现不了
    -----------------------------------
    怎么实现不了?报错? 查不出数据?
    2。
    SELECT name,age,time from biao where time=#" + TextBox1.Text.tostring + "#
    -----------------------------------
    语句并没有错,确保数据库中具有你输入的时间的记录
      

  3.   

    select   *   from   table1   where   出生年月   like   #3/21/1980#可以具体到天
      

  4.   

    Jinglecat(晓风残月)
    这位大哥帮帮忙
    我的错误是查不出数据,并不抱错
      

  5.   

    "select name,age,time from biao where datediff(day,time,'"+TextBox1.Text.tostring()+"')=0"
      

  6.   

    对了,time是关键字,所以规范的写法应该是
    "select name,age,[time] from biao where datediff(day,[time],'"+TextBox1.Text.tostring()+"')=0"
      

  7.   

    1.
    用 > 或者 < 试试, 可能是精度的问题:string sql = "SELECT name,age,time from biao where time > #" + TextBox1.Text.tostring + "#"2.
    贴出完整代码看看, 是否有其他忽略的问题?
      

  8.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.Odbc;
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TextBox1.Text = DateTime.Now.ToString("yyyy-MM-dd");       
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            OdbcConnection con = new OdbcConnection("DSN=haha");
            try
            {
                con.Open();
                DateTime chaxun = Convert.ToDateTime(TextBox1.Text.ToString().Trim());
                OdbcDataAdapter da = new OdbcDataAdapter("SELECT name,age,shijian from biao where shijian=#"+chaxun+"#", con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                this.GridView1.DataSource = ds;
                this.GridView1.DataBind();
                Response.Write("<script language =javascript>alart('成功')</script>");
            }
            catch
            {
                Response.Write("<script language =javascript>alart('失败')</script>");
            }    }
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {    }
    }
      

  9.   

    调试程序的时候别用trycatch,不然怎么出错都不知道,应该不是查询语句本身的问题
      

  10.   

    SELECT name,age,convert(nvarchar(10),shijian,111) as colTime from biao where colTime=#"+chaxun+"#试一下这样可以吗?好像你的不符
      

  11.   

    1.
    使用 FORMAT 试试string sql = String.Format("SELECT name,age,shijian from biao where format(shijian, 'yyyy-mm-dd')=#{0}#", DateTime.Now.ToString("yyyy-MM-dd"));注意: 格式符号 'yyyy-mm-dd' 一定要对应, 因为这里实际上是按字符串比价2.
    更倾向于使用 BETWEENDateTime begin = Convert.ToDateTime(TextBox1.Text.ToString().Trim());;
    DateTime end = end.AddDays(1); // 偏移量按自己需求
    string sql = String.Format("SELECT name,age,shijian from biao where shijian between #{0}# and #{1}#", begin.ToString(), end.ToString());Hope helpful!
      

  12.   

    l_strWhere+="pld_dProducttionData=#"+Convert.ToDateTime(this.txtdPDate.Text.Trim()).ToShortDateString().ToString().Trim()+"#";
      

  13.   

    哈哈哈哈,解决了!!
    DateTime begin = Convert.ToDateTime(TextBox1.Text.ToString().Trim());;
    DateTime end = end.AddDays(1); // 偏移量按自己需求
    应该是DateTime end = begin.AddDays(1); // 偏移量按自己需求b吧??
    总算是能查了,但是还是要跟着小时,分秒
    现在输入2007-06-07 14:23:78 能查出结果了,但是能不能不输入14:23:78 呢?
      

  14.   

    成功!!!!Jinglecat(晓风残月) 这位大哥!!太感谢你了!!!
    你帮了我大忙了!!!
    万分感谢!!!
    怎么给你分啊??
      

  15.   

    但是能不能不输入14:23:78 呢?
    -------------------
    不输入日期的时候,1.
    系统会自动用默认日期值代替, Access 中好像是 1889-12-312.
    所以, 你最好判断下, 如果没有输入日期, 手动加上当前的日期