代码如下: procedure TSys_Login_Fm.BitBtn2Click(Sender: TObject); begin MainKJ_Fm.Close; end;
procedure TSys_Login_Fm.Button1Click(Sender: TObject); var sql:string; var empname:string; var TD:TTransactionDesc; begin try TD.TransactionID:=1222; TD.IsolationLevel:=xilREADCOMMITTED; ClientModule1.SQLConnection1.StartTransaction(TD);
sql:=' use FcQYGL '; empname:='张三'; sql:=sql+' insert into SysLoginSet (LoginUserName) values ('''+empname+''') '; ClientModule1.execsql(3,sql);
sql:=' use FcQYGL '; empname:='李四'; sql:=sql+' insert into SysLoginSet (LoginUserName) values ('''+empname+''') '; ClientModule1.execsql(3,sql);
sql:=' use FcQYGL '; empname:='王五'; sql:=sql+' insert into SysLoginSet (LoginUserName) values ('''+empname+''') '; ClientModule1.execsql(3,sql);
sql:=' use FcQYGL '; empname:='周六'; sql:=sql+' insert into SysLoginSet (LoginUserName1) values ('''+empname+''') '; ClientModule1.execsql(3,sql);
ClientModule1.SQLConnection1.Commit(TD);
showmessage('执行完毕!'); except On E:Exception do begin ClientModule1.SQLConnection1.Rollback(TD) ;
function TClientMOdule1.execsql(ExeType:Integer;sql: string): string; begin // 简单查询使用 1 // 简单更新使用 2 // 需要事务更新使用 3 if ExeType=1 then begin ClientDataSet1.Close; ClientDataSet1.CommandText:=sql; ClientDataSet1.Open; end else if ExeType=2 then begin ClientDataSet1.Close; ClientDataSet1.CommandText:=sql; ClientDataSet1.Execute; end else if ExeType=3 then begin ClientDataSet1.Close; ClientDataSet1.CommandText:=sql; ClientDataSet1.Execute; end; Result:='0'; end;
----------------------------------------------
偶尔做做代码应付一下工作,却发现Delphi已成必配
first: 1) why you try idendify the "ID" transaction ? ---> this should be done by "database", NOT YOU!!!
2) SQLConnection1.StartTransaction( n ) ---> Note: StartTransaction has been deprecated. ------> Use BeginTransaction instead. // EndTransaction!
try some like this:
procedure TForm1.Button2Click(Sender: TObject); var MyDBXTransaction: TDBXTransaction; begin if not SQLConnection1.InTransaction then begin try MyDBXTransaction := SQLConnection1.BeginTransaction; // // .... ClientDataset post... // SQLConnection1.CommitFreeAndNil(MyDBXTransaction); except SQLConnection1.RollbackFreeAndNil(MyDBXTransaction); end; end; end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
function ChoiceASQLForUsage(const AChoice:integer) : string; begin result := ''; // if (AChoice in [0 .. 2]) then result := MySQLText[MySQLChoiced]; end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
THIS methods IS DEPRECATED USAGE: DONT USE IT ANYMORE - ClientModule1.SQLConnection1.Commit(TD); - ClientModule1.SQLConnection1.Rollback(TD) ;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
MySQLText: TMySQLText = ( 'select * from TableX where ID=%d', // to integer values 'select * from TableX where name=%s', // to string values 'select * from TableX where fieldX=%s' // .... );
... if (MySQL<>'') then ShowMessage( Format(MySQL, [ ValueXXXX_type_expected ] ) );
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
ClientDataSet1.CommandText:=sql; ClientDataSet1.Open; // select
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
按照: first: 1) why you try idendify the "ID" transaction ? ---> this should be done by "database", NOT YOU!!!
2) SQLConnection1.StartTransaction( n ) ---> Note: StartTransaction has been deprecated. ------> Use BeginTransaction instead. // EndTransaction!
try some like this:
procedure TForm1.Button2Click(Sender: TObject); var MyDBXTransaction: TDBXTransaction; begin if not SQLConnection1.InTransaction then begin try MyDBXTransaction := SQLConnection1.BeginTransaction; // // .... ClientDataset post... // SQLConnection1.CommitFreeAndNil(MyDBXTransaction); except SQLConnection1.RollbackFreeAndNil(MyDBXTransaction); end; end; end; 出现:
SQLConnection1.BeginTransaction(TDBXIsolations.ReadCommitted)
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
SQLcon.CommitFreeAndNil(dbxTR);
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3