我在信息录入的时候是用一个DateTimePicker控件进行时间的保存,在数据库里设置时间的类型是datetime,但在查询时我用的是Edit来接收输入的信息,这样好象就不能查询出来,请问要经过怎样的类型转换才能查出

解决方案 »

  1.   

    用formatdatetime
    例子:FormatDateTime('yyyy-mm-dd',DateTimePicker.date)
      

  2.   

    曾经也遇到这个问题,后来想了一个大家可能是推荐的做法把数据库data型改为char型。
    里面数据格式就是2006-05-05 输入数据的时候就用 FormatDateTime('yyyy-mm-dd',DateTimePicker.date)这样,用edit来查询也方便,比较大家都是字符形了嘛。
      

  3.   

    我写的是
     with Query1 do
    begin
         SQL.Clear;
         SQL.Add('select goods.goods_id 商品编号,goods.class 类别,goods.goods_name 商品名称,goods.produce_area 产地,goods.validity_date 有效日期,stock.purchase_price 进价,stock.number 数量,stock.stock_id 库存号');
         SQL.Add('from goods,stock');
         SQL.Add('where goods.goods_id=stock.goods_id ');
         SQL.Add(Format('and goods.validity_date=''%s''',[Trim(Edit1.Text)]));
        Open;
    end; 请问应该怎么改
      

  4.   

    SQL.Add(Format('and goods.validity_date=''%s''',[Trim(Edit1.Text)]));
    改成
    SQL.Add('and goods.validity_date=' + QuotedStr(FormatDatetime('yyyy-mm-dd',Edit1.Text)));
      

  5.   

    错了,应该是
    SQL.Add('and goods.validity_date=' + QuotedStr(FormatDatetime('yyyy-mm-dd',DateToStr(Edit1.Text))));
    或者如果很规范的化,并且数据库可以隐式转换的化,就
    SQL.Add('and goods.validity_date=' + QuotedStr(Edit1.Text);