着段代码何错之有? if bz='insert' then begin YDLRADOTABLE1.Close; YDLRADOTABLE1.connection:=mainform.ADOConnection1; YDLRADOTABLE1.tablename:= 'YDtemp'; end; dbgrid1.ReadOnly:=false; datasource1.DataSet:=YDLRADOTABLE1; dbgrid1.DataSource:=datasource1; if i<10 then xh1:='D000000'+inttostr(i) else if i<100 then xh1:='D00000'+inttostr(i) ELSE if i<1000 then xh1:='D0000'+inttostr(i) ELSE if i<10000 then xh1:='D000'+inttostr(i) ELSE if i<100000 then xh1:='D00'+inttostr(i) ELSE if i<1000000 then xh1:='D0'+inttostr(i) ELSE xh1:='D'+inttostr(i); // YDLRADOTABLE1.Close; // YDLRADOTABLE1.connection:=mainform.ADOConnection1; // YDLRADOTABLE1.tablename:= 'khtemp'; if YDLRADOTABLE1.Active = false then try YDLRADOTABLE1.active:=true; except Application.Terminate; end; YDLRADOTABLE1.Append; dbgrid1.Columns[0].fieldname:='FHYK'; // dbgrid1.Columns[0].readonly:=true; dbgrid1.Columns[1].fieldname:='GCH'; dbgrid1.Columns[2].fieldname:='CPH'; dbgrid1.Columns[3].fieldname:='SJY'; dbgrid1.Columns[4].fieldname:='YPDM'; dbgrid1.Columns[5].fieldname:='A22'; dbgrid1.Columns[6].fieldname:='GJS'; dbgrid1.Columns[7].fieldname:='MD'; dbgrid1.Columns[8].fieldname:='GH'; dbgrid1.Columns[9].fieldname:='SHR'; with YDLRADOTABLE1 do begin FieldByName('rq').Value:=maskedit1.text; FieldByName('SJ').Value:=TIMETOSTR(NOW); FieldByName('CPH').Value:='川C'; FieldByName('YPDM').Value:='090'; FieldByName('FHYK').Value:='01:舒平'; FieldByName('A22').Value:=0; FieldByName('GJS').Value:=0 ; FieldByName('MD').Value:=0; FieldByName('GH').Value:='01'; FieldByName('DM').Value:=MAINFORM.JYZDM; FieldByName('SS').Value:=0; FieldByName('CZY').Value:=MAINFORM.kprxm; end; YDLRADOTABLE1.Refresh; i:=i+1; bz:='';
begin
YDLRADOTABLE1.Close;
YDLRADOTABLE1.connection:=mainform.ADOConnection1;
YDLRADOTABLE1.tablename:= 'YDtemp';
end;
dbgrid1.ReadOnly:=false;
datasource1.DataSet:=YDLRADOTABLE1;
dbgrid1.DataSource:=datasource1;
if i<10 then
xh1:='D000000'+inttostr(i)
else if i<100 then
xh1:='D00000'+inttostr(i)
ELSE if i<1000 then
xh1:='D0000'+inttostr(i)
ELSE if i<10000 then
xh1:='D000'+inttostr(i)
ELSE if i<100000 then
xh1:='D00'+inttostr(i)
ELSE if i<1000000 then
xh1:='D0'+inttostr(i)
ELSE
xh1:='D'+inttostr(i);
// YDLRADOTABLE1.Close;
// YDLRADOTABLE1.connection:=mainform.ADOConnection1;
// YDLRADOTABLE1.tablename:= 'khtemp';
if YDLRADOTABLE1.Active = false then
try
YDLRADOTABLE1.active:=true;
except
Application.Terminate;
end;
YDLRADOTABLE1.Append;
dbgrid1.Columns[0].fieldname:='FHYK';
// dbgrid1.Columns[0].readonly:=true;
dbgrid1.Columns[1].fieldname:='GCH';
dbgrid1.Columns[2].fieldname:='CPH';
dbgrid1.Columns[3].fieldname:='SJY';
dbgrid1.Columns[4].fieldname:='YPDM';
dbgrid1.Columns[5].fieldname:='A22';
dbgrid1.Columns[6].fieldname:='GJS';
dbgrid1.Columns[7].fieldname:='MD';
dbgrid1.Columns[8].fieldname:='GH';
dbgrid1.Columns[9].fieldname:='SHR';
with YDLRADOTABLE1 do
begin
FieldByName('rq').Value:=maskedit1.text;
FieldByName('SJ').Value:=TIMETOSTR(NOW);
FieldByName('CPH').Value:='川C';
FieldByName('YPDM').Value:='090';
FieldByName('FHYK').Value:='01:舒平';
FieldByName('A22').Value:=0;
FieldByName('GJS').Value:=0 ;
FieldByName('MD').Value:=0;
FieldByName('GH').Value:='01';
FieldByName('DM').Value:=MAINFORM.JYZDM;
FieldByName('SS').Value:=0;
FieldByName('CZY').Value:=MAINFORM.kprxm;
end;
YDLRADOTABLE1.Refresh;
i:=i+1;
bz:='';
或MS sql2000等MS的数据库, 不用第3方控件情况下, 用ADO是较好的选择.
BDE始终是个'FAT' client, 不好安装, 你还可以考虑用DB Express或Delphi
所提供的其他如ClientDataSet等做.同时多用 SQL 来做数据库项目, 当你是用ADOTable来连MSSQL时, 会较用ADOQuery 或 ADOCommand等以sql为中心的控件的问题较多. ADOTable只适合
单用户操控, 纪录又少, 不会同时被多人同时更新的情况下时用的.
怎么升级
就算不能解你这个问题,也会有很多其它好处的(不用我说了吧)
记住,如果用ADO,非万不得已不要用ADOTable,那是为了兼容BDE的某些功能而存在的一个东东,只是把ADORecordSet多封装了些而已,用着简单了,问题也就多多了!
再有,你用的是什么数据库,如果是Oralce之类的第三方的产品,最好去找官方出的OLE DB Provider程序,不然可能会有问题,最起码Oracle是这样!
这个错误我碰到过,原来是触发器在我Post后更新了数据,导致
后面更新时找不到更新前同样的纪录。在edit前,refresh一把就好了。