在我建的person表中,有一个birthday的日期字段,通过bithday字段查询记录,我写了两种sql语句:
第一种:
  with ADOQuery1 do
  begin
    Close;
    Sql.Text := 'select * from person where birthday='+DateToStr(DateTimePicker1.Date);
    Open;
  end;
第二种:
  with ADOQuery1 do
  begin
    Close;
    Sql.Text := 'select * from person where birthday=:birth';
    Parameters.ParamByName('birth').Value := DateTimePicker1.Date;
    Open;
  end;
两种语句应该都没有错,但是第一种查询不到记录,不知为什么?

解决方案 »

  1.   

    ACCESS: 
    Sql.Text := 'select * from person where birthday=#'+DateToStr+datetimepicker1.date+'#';MS SQL: 
    Sql.Text := 'select * from person where birthday='+#39+DateToStr+datetimepicker1.date+#39;
      

  2.   


    with ADOQuery1 do
      begin
        Close;
        Sql.Text := 'select * from person where  birthday='+''''+DateToStr(DateTimePicker1.Date)+'''';
        Open;
      end;
      

  3.   

    第一种应为:
      Adoquery1.paramcheck:=False;
      with ADOQuery1 do
      begin
        Close;
        Sql.Text := 'select * from person where birthday=#'''+DateToStr(DateTimePicker1.Date)+'#''';
        Open;
      end;
    不建议使用第二种