代码如下;
with DS.Connection.Transaction do
begin
lTransactionHandle := Start(False); //启动事务 Start
try
DS.ApplyUpdates;
if not TINFO_LJCGRK(InfoBroker.Info).updateStockKC_SAVE(FOperstatus) then raise exception.Create('更新库存信息失败');
Commit(lTransactionHandle); // 提交事务
if ChkSavePrint.Checked then
begin
TINFO_LJCGRK(InfoBroker.Info).PreparePrintView(DS.FieldByName('ID').asString);
TSheetDoc(RptView.doc).exporter.Printex(false, true);
// RptView.Print ;
end;
if (Sender as TToolButton).Caption ='保存' then
ModalResult:=Business.Forms.Controls.mrOk
else begin
FOperstatus:='新增';
DisplayRecord;
if DataEdtPCODE.CanFocus then DataEdtPCODE.SetFocus ;
end;
except
Rollback(lTransactionHandle); //回滚事务
raise;
end;
end;
static function TWSL.GetDataSetBySQL(strSQL:String)bject; //根据提交的SQL文本返回数据集
var
lDS : TQuery;
begin
lDS:=TQuery.Create(nil);
try
try
lDS.ConnectionString:='DATABASEURL=Biz:ECISECISDB.Database';
lDS.CommandText:=strSQL;
lDS.Open;
except
on E: Exception do
raise exception.Create('执行SQL语句失败,SQL文本:'+strSQL+' 异常内容:'+E.Message); end;
Result:=lDS.Data;
finally
lDS.Free;
end;
end;