写sql语句,我又个插入的例子,你可参考一下:
function Tmid.insertsheet(datamaster, datadetail: OleVariant): HResult;
var
ipp:iappserver;
p,k
levariant;
cds,cds1:Tclientdataset;
s,s1,s2,s3:string;
n,x,icount:integer;
trans:ITransactioncontextEx;
idm:Itrainrdm;
begin
trans:=CreateTransactionContextEx;
try
olecheck(Trans.createinstance(class_trainrdm,iid_itrainrdm,idm));
//ipp:=cotrainrdm.create;
ipp:=idm as Iappserver;
cds:=TClientDataSet.create(nil);
cds1:=TClientDataSet.create(nil);
cds.data:=datamaster;
s:='insert tb_train_master(sheetid,senddate,worker) values(''%s'',''%s'',''%s'')';
cds1.data:=datadetail;
s1:='insert tb_train_detail(sheetid,gname,number,price) values(''%s'',''%s'',%s,%g)';
n:=0;
try
cds1.first;
for icount:=0 to cds1.RecordCount-1do
begin
s2:=format(s1,[cds1.fieldbyname('sheetid').asstring,
cds1.fieldbyname('gname').asstring,
cds1.fieldbyname('number').asstring,
cds1.fieldbyname('price').asfloat]);
ipp.AS_Execute('DataSetProvider1',s2,p,k);
cds1.Next;
n:=n+1;
end;
cds.first;
for x:=0 to cds.recordcount-1do
begin
s3:=format(s,[cds.fieldbyname('sheetid').asstring,
cds.fieldbyname('senddate').asstring,
cds.fieldbyname('worker').asstring]);
ipp.AS_Execute('DataSetProvider1',s3,p,k);
cds.next;
end;
showmessage('n is '+inttostr
);
trans.Commit;
except
trans.Abort;
showmessage('no');
end;
finally
cds.free;
cds1.free;
end;
end;
function Tmid.deletesheet(sheetid: OleVariant): HResult;
var
ipp:iappserver;
s,s1:string;
p,k
levariant;
begin
try
ipp:=cotrainrdm.Create;
s:='delete from tb_train_master where sheetid=%s';
s:=format(s,[sheetid]);
s1:='delete from tb_train_detail where sheetid=%s';
s1:=format(s1,[sheetid]);
try
ipp.AS_Execute('DataSetProvider1',s1,p,k);
ipp.AS_Execute('DataSetProvider1',s,p,k);
setcomplete;
except
showmessage('delete is fail');
setabort;
end;
except
showmessage('try is fail');
end;
end;
在MTS环境中。