查询语句是SELECT 产品流程日报表.机号,产品流程日报表.生产操作员  FROM 产品流程日报表 where (产品流程日报表.日期='"+sj+"') sj是string类型,当前值是2009-12-30,数据库里面的字段"日期"的数据类型是日期型,而且数据库里面有2009-12-30这个时间的数据,但是总是查询不到数据,请帮忙看一下原因

解决方案 »

  1.   

    那就在日期那里别用=号,如下形式:
    日期>=2009-12-30 00:00:00 &&日期<=2009-12-30 23:59:59 
      

  2.   

    LZ使用预处理了吗?感觉应该是类型不匹配的缘故sqlcommand.CommandText = "select * from 表名 where n=@n";  //n为表中的日期列名
                sqlcommand.Parameters.Add("@n", SqlDbType.DateTime);
                sqlcommand.Parameters["@n"].Value = xxxxxxx;
      

  3.   

    两个方法,
    第一个
    datetime dt1=convert.todatetime(sj+" 0:00:00");
    datetime dt2=convert.todatetime(sj+" 23:59:59");
    sql="SELECT 产品流程日报表.机号,产品流程日报表.生产操作员  FROM 产品流程日报表 where 产品流程日报表.日期 between '"+dt1+"' and '"+dt2+"'";
    第二个
    datetime dtm=convert.todatetime(sj);
    sql="SELECT 产品流程日报表.机号,产品流程日报表.生产操作员  FROM 产品流程日报表 where year(产品流程日报表.日期)="+dtm.year+" and month(产品流程日报表.日期)="+dtm.month+" and day(产品流程日报表.日期)="+dtm.day+"";
      

  4.   

    失误,发现LZ查的是access,那使用的应该是OleDB名称空间下的方法
    修改如下
           OleDbCommand oledbcommand;
           oledbcommand.CommandText = "select * from 表名 where n=@n";  //n为表中的日期列名
                oledbcommand.Parameters.Add("@n", OleDbType.DBDate);
                oledbcommand.Parameters["@n"].Value = xxxxxxx;
      

  5.   

    我改后的代码是
    string sj = TextBox1.Text.Trim();
    string yuju = "SELECT 产品流程日报表.机号,产品流程日报表.生产操作员  FROM 产品流程日报表 where  产品流程日报表.日期=@日期"; 
            OleDbCommand oledbcmd = new OleDbCommand(yuju, oledbcon);
            oledbcmd.Parameters.Add("@日期", OleDbType.DBDate);
            oledbcmd.Parameters["@日期"].Value = sj;
            OleDbDataReader odr = oledbcmd.ExecuteReader();
            OleDbDataAdapter olesda = new OleDbDataAdapter(yuju, oledbcon);
            DataSet ds = new DataSet();
            olesda.Fill(ds, "dat");
            GridView1.DataSource = ds.Tables["dat"];
            GridView1.DataBind();
    他在执行到olesda.Fill(ds, "dat");这句话的时候提示
    至少有一个参数未指定值