|
发表于 2012-6-4 08:22:57
|
显示全部楼层
本帖最后由 乐yi忘忧 于 2012-6-12 23:30 编辑
procedure TForm1.FormCreate(Sender: TObject);
begin
With ADOConnection1 do
begin
Close;
ConnectionString:='Provider=Microsoft.Jet.OlEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName){(ParamStr(0))}+'\database\个人应缴.mdb;User ID=admin; Password=; Persist security Info=False';//修改这里,读取数据库路径
LoginPrompt:=False;
end;
With ADOQuery1 do
begin
Connection:=ADOConnection1;
CursorLocation:= clUseServer;
Close;
SQL.Clear;
SQL.Add('SELECT 导入应征清册.序号,姓名,公民身份证,银行账号,应缴金额,档次变更,村委会名称,村小组,缴费类别,导入应征清册.备注 ');
SQL.Add('FROM ([04基本信息] INNER JOIN 导入应征清册 ON [04基本信息].公民身份证=导入应征清册.公民身份证号) INNER JOIN [02村委会编码] ON [04基本信息].村委会编码=[02村委会编码].村委会编码');
Open;
end;
ADOQuery2.Connection:=ADOConnection1;
DataSource1.DataSet:= ADOQuery1;
DBGrid1.DataSource:= DataSource1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
CursorLocation:= clUseServer;
Close;
SQL.Clear;
SQL.Add('SELECT 导入应征清册.序号,姓名,公民身份证,银行账号,应缴金额,档次变更,村委会名称,村小组,缴费类别,导入应征清册.备注 ');
SQL.Add('FROM ([04基本信息] INNER JOIN 导入应征清册 ON [04基本信息].公民身份证=导入应征清册.公民身份证号) INNER JOIN [02村委会编码] ON [04基本信息].村委会编码=[02村委会编码].村委会编码');
SQL.Add('where [04基本信息].公民身份证 like ''%'+edit1.Text+'%''');
Open;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then { 判断是按执行键}
Button1.Click
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
sCmd:String;
begin
sCmd:='';
ADOQuery1.Edit;
ADOQuery1.Post;
ADOCommand1.Connection:=ADOConnection1;
//ADOCommand1.ConnectionString:='Provider=Microsoft.Jet.OlEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName){(ParamStr(0))}+'\database\个人应缴.mdb;User ID=admin; Password=; Persist security Info=False';//修改这里,读取数据库路径
//If Trim(Adoquery1.FieldBYName('档次变更').AsString)<>'' then
sCmd:='Select * from sheet11 where 公民身份证='''+Adoquery1.FieldBYName('公民身份证').AsString+'''';
With ADoQuery2 do
begin
SQL.Clear;
SQL.Add(sCmd);
Open;
end;
If Adoquery2.RecordCount=0 Then
begin
sCmd:='Insert into Sheet11 Select 导入应征清册.序号,姓名,公民身份证,银行账号,应缴金额,档次变更,村委会名称,村小组,缴费类别,导入应征清册.备注 FROM ([04基本信息] Left JOIN';
sCmd:=sCmd+' 导入应征清册 ON [04基本信息].公民身份证=导入应征清册.公民身份证号) Left JOIN [02村委会编码] ON [04基本信息].村委会编码=[02村委会编码].村委会编码 where 公民身份证='''+Adoquery1.FieldBYName('公民身份证').AsString+'''';
ADOCommand1.CommandText := sCmd;
ADOCommand1.Execute();
end
else
Showmessage('已经保存过记录,不要重复保存。');
end; |
|