谢谢各位的答复:
用两个conn是因为用到了两个不同的库,insert into 语句是从当前库追加到另一个库的
p1表中,不知有没有好办法用一个conn
现附上原代码,刚从vb 转向delphi,各位不要笑我的编码
procedure TForm1.Button1Click(Sender: TObject);
var
FileNameAll,ImgFileName,JTH:string;
FileNameLen:integer;
connstr:string;
recc:integer;
imgnum,intpage,code:integer;
pagetemp:string;
begin
rshldlinkinfo.First;
ConnHldCjg.Execute('delete * from p2');
while not RSHldLinkInfo.Eof do
begin
label1.Caption:='正在转换'+rshldlinkinfo.Fieldbyname('zymc').AsString;
button1.Enabled:=true;
FileNameAll:=trim(rshldlinkinfo.Fieldbyname('zymc').AsString);
FileNameLen:=length(FileNameAll);
ImgFileName:=copy(FileNameAll,1,FileNameLen-3); //此处的imgfile不完整
JTH:=copy(FileNameAll,FileNameLen-3+1,3);
connstr:='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source='+'//Server/WorkDbf/HLDCJG/'+JTH+'/'+FileNameAll+'.MDB;'+
'Persist Security Info=False';
if stopen in CONNHLDFILELINK.State then
begin
CONNHLDFILELINK.Connected:=false;
end;
CONNHLDFILELINK.ConnectionString:=CONNSTR; //打开连结文件的CONN
CONNHLDFILELINK.Open;
RSHldLinkFileP2.Connection:=CONNHLDFILELINK;
RSHldLinkFileP2.CommandType:=cmdTable;
RSHldLinkFileP2.CommandText:='p2';
RSHldLinkFileP2.Open;
ConnHldCjg.Execute('DELETE * FROM P1',recc); //将CJG的P1表清空
Application.ProcessMessages;
CONNHLDFILELINK.Execute('INSERT INTO p1 IN '+''''+'E:/soft/HLDCJGLR/LINK/HLDcjg.mdb'+''''+
' SELECT * FROM p2',recc); //追加连结文件到正表中
//原来这有一行SQL ConnHldCjg.Execute('update p1 from page="000"+p1.page');
(现在临时补的,可能语法有错,不过原来在前面加Sleep(5000)时执行正确,否则这条语句无效)
sleep(5000);
rshldcjgp1.Active:=false;
rshldcjgp1.Active:=true; //这里打开是为了让RSHLDCJGP1得到最新的数据
我在把RSHLDCJGP1的CursorLocation设为CluseClient
时发现RSHLDCJGP1得到的RecordCount数竟然不对,显示为
827条实际在access中为830条不知何故???只能将CursorLocation改为ClUseServer
可又不支持REFRESh功能.
RSHldCjgP1.First;
val(ImgFileName,imgnum,code);
while not RSHldCjgP1.Eof do
begin
pagetemp:=RSHldCjgP1.fieldbyname('page').AsString;
val(pagetemp,intpage,code);
pagetemp:=FillUpZero(trim(IntToStr(imgnum+intpage-1)));
rshldcjgp1.Edit;
RSHldCjgP1.fieldbyname('page').AsString:=pagetemp;
rshldcjgp1.Post; //************不加SLeep(5000)时在这行出错,估计是上面的sql还未执行完!
label2.Caption:='第'+inttostr(rshldcjgp1.RecNo)+'/'+inttostr(recc);
Application.ProcessMessages;
RSHldCjgP1.Next;
end;
ConnHldCjg.Execute('INSERT INTO p2 SELECT * FROM p1');
RSHldLinkInfo.Next
end;
ShowMessage('ok');
exit;
end;