procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:=FormatDateTime('YYYY-MM-DD',now);
end;procedure TForm1.Button1Click(Sender: TObject);
var ADay:TDateTime;
begin
ADay:=StrToDate(Edit1.Text);
Query1.SQL.Text:='insert into test.db (MyDate) values (ADay)';
Query1.ExecSQL;
Query1.Close;
end;
上面的代码是错误的,变量值传不过去。MyDate字段是日期类型。
简单的向数据库中插入日期类型数据,但是不知道在DELPHI中怎样把变量值传给SQL语言中,请大家帮帮我。很简单的一个问题。
begin
Edit1.Text:=FormatDateTime('YYYY-MM-DD',now);
end;procedure TForm1.Button1Click(Sender: TObject);
var ADay:TDateTime;
begin
ADay:=StrToDate(Edit1.Text);
Query1.SQL.Text:='insert into test.db (MyDate) values (ADay)';
Query1.ExecSQL;
Query1.Close;
end;
上面的代码是错误的,变量值传不过去。MyDate字段是日期类型。
简单的向数据库中插入日期类型数据,但是不知道在DELPHI中怎样把变量值传给SQL语言中,请大家帮帮我。很简单的一个问题。
Query1.SQL.Text:='insert into test.db (MyDate) select ' + ADay;
var ADay:TDateTime;
begin
ADay:=StrToDate(Edit1.Text);
Query1.SQL.Text:='insert into test.db (MyDate) values (:mydate)';
Query1.ParamByName('mydate').value := ADay;
Query1.ExecSQL;
Query1.Close;
end;