小弟想写一条sql语句:
insert into table1 (日期) values (?)
其中‘?’处想取系统当前年份加1,月和日都是1
比如现在是2004年,那么希望在表中插入2005-1-1
请问该如何实现? 由于我初次接触delphi,所以问题比较弱,不过还是提供了100分给回应的大侠!
多谢多谢!
insert into table1 (日期) values (?)
其中‘?’处想取系统当前年份加1,月和日都是1
比如现在是2004年,那么希望在表中插入2005-1-1
请问该如何实现? 由于我初次接触delphi,所以问题比较弱,不过还是提供了100分给回应的大侠!
多谢多谢!
query1.sql.add('insert into table1 (日期) values (:datetime)');
query1.query1.ParamByName(日期) .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now(),1));
query1.ExecSQL;
代码:
var
Year, Month, Day, DOW: Word;
date:tdatetime;
s1,s2:string;
date:=DateTimePicker1.DateTime;
DecodeDateFully(Date, Year, Month, Day, DOW);
if month<10 then s1:='0'+inttostr(month) else s1:=inttostr(month);
if Day<10 then s2:='0'+inttostr(Day)else s2:=inttostr(Day);
suiedit5.Text:=inttostr(Year)+'-'+s1+'-'+s2;
sDate :string;
Year :word;
begin
Year :=YearOf(Date);
sDate :=DateToStr(EncodeDate(Year,1,1));
sSQL :='Insert into TableName (ColumnName...)Values('sDate');
uses DateUtils;with adoquery1 do
try
sql.clear;
sql.add('insert into table1 (日期) values (:dt)');
ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now (),1));
ExecSQL;
except
showmessage('插入失败!');
end;
如果access
uses DateUtils;with adoquery1 do
try
sql.clear;
sql.add('insert into table1 (日期) values (:dt)');
ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now (),1));
ExecSQL;
except
showmessage('插入失败!');
end;
with adoquery1 do
try
sql.clear;
sql.add('insert into table1 (日期) values (:dt)');
ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now),1));
ExecSQL;
except
showmessage('插入失败!');
end;