procedure Thjf.Button2Click(Sender: TObject); begin if (edit1.Text='') then begin showmessage('数据输入不完全,请输入完全再试'); exit; end; try with ADODataSet1 do begin Active:=false; ConnectionString:=main.cnnstr; CommandText:='select * from hj'; Active:=true; Insert;//插入模式 edit; //编辑模式,也可添加 append;//添加模式 end; with DataSource1.DataSet.Fields do begin Fields[0].Value:=strtotime(edit1.Text); end; ADODataSet1.Post; showmessage('数据添加成功!'); except showmessage('数据添加失败'); end; end;
begin
if (edit1.Text='') then
begin
showmessage('数据输入不完全,请输入完全再试');
exit;
end;
try
with ADODataSet1 do
begin
Active:=false;
ConnectionString:=main.cnnstr;
CommandText:='select * from hj';
Active:=true;
Insert;//插入模式
edit; //编辑模式,也可添加
append;//添加模式
end;
with DataSource1.DataSet.Fields do
begin
Fields[0].Value:=strtotime(edit1.Text);
end;
ADODataSet1.Post;
showmessage('数据添加成功!');
except
showmessage('数据添加失败');
end;
end;
Main.cnnstr是连接字符串,
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+getcurrentdir+'数据库名称.mdb;Persist Security Info=False';
这是ACCESS数据库,如果是ODBC,
Provider=MSDASQL.1;Persist Security Info=False;Data Source=ODBC数据库名称