Program, using a ADOQuery ExecSQL execute a SQL statement, how to know the execution result is success or failure?
How to see the results of the return value?
Someone said that the successful return 1 returns 0, failure, how to see the return value?
CodePudding user response:
This is the return value adoquery1. Recordcount
CodePudding user response:
Wrong, is the number of rows returned
CodePudding user response:
Try
ADOQuery1. ExecSQL;
Except,
Showmessage (" ERROR ");
end;
CodePudding user response:
The
reference bihai reply: 3/f try ADOQuery1. ExecSQL; Except, Showmessage (" ERROR "); end; To determine whether a SQL statement error can be in accordance with this CodePudding user response:
Reference structure TRY EXCEPT, The END; CodePudding user response:
reference 5 floor sgzhou12345 reply: reference structureTRY EXCEPT, The END; Can put the SQL statements in a function, through the exception handling return value to determine whether successful, The function ExceSQLTxt: Boolean; The begin Result:=false; Try {executing SQL statements} Result:=true; {} statement execution success Except, Result:=false; {} statement execution failure end; end; {OR} The function ExceSQLTxt: string; The begin Result:='; Try {executing SQL statements} Result:='; {} statement execution success Except, On e: the exception Result:=e.m essage. {} statement execution fails, return failure information end; end; CodePudding user response:
The unit Unit1; Interface USES the Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, the ADODB library; Type TForm1=class (TForm) ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; For: TButton; ListBox1: TListBox; Procedure Button1Click (Sender: TObject); Private {Private declarations} Public {Public declarations} end; Var Form1: TForm1; Implementation {$R *. DFM} Procedure getADOConnectionError (vSql: string; VError: TStrings; VQuery: TADOQuery); Procedure execSQL (vSql: string; VQuery: TADOQuery); The begin With vQuery do The begin The Close; SQL. The Clear; SQL. Text:=vSql; The Open; end; end; Var I: Integer; The begin With vQuery. Connection do Try ExecSQL (vSql vQuery); Except, //the total number of errors //vError. Add (IntToStr (ConnectionObject. Errors. Count)); VError. The Clear; For I:=0 to ConnectionObject. Errors. Do the Count - 1 The begin VError. Add (' error code='+ IntToStr (ConnectionObject. Errors [I] Number)); VError. Add (='+' error Source ConnectionObject. Errors [I] Source); VError. Add (' error source raw code='+ IntToStr (ConnectionObject. Errors [I] NativeError)); VError. Add (' error message='+ ConnectionObject. Errors [I] the Description). end; Exit; end; end; Procedure TForm1. Button1Click (Sender: TObject); The begin GetADOConnectionError (' select * AA BB, ListBox1 Items, ADOQuery1); end; End. CodePudding user response:
My method is to use the exception handling TRY EXCEPT, END If there are problems will quote the statement execution, If the statement is executed without the problem, but I don't want the result of the execution, such as transaction rollback, I'll check the confirm if successful, CodePudding user response:
. With qry2 do begin The close; SQL. The Clear; SQL. The Add (' DECLARE @ db_id int, @ tbl_id int "); SQL. The Add (' USE DRN '); SQL. The Add (' SET @ db_id=db_id (' + quotedstr (' DRN) + ') '); SQL. The Add (' SET @ tbl_id=OBJECT_ID (' + quotedstr (' [DRN]. [dbo] [lldata_ '+ tabledate +'] ') + ') '); SQL. The Add (' DBCC PINTABLE (@ db_id, @ tbl_id) '); Execsql; end; . Execsql performed successfully, but return 1 is what mean? CodePudding user response:
ExecSQL execution returns the number of rows affected, "influence", including increased when for example ExecSQL perform a delete statement 3 records, the three conditions were deleted successfully return 3 (only successfully deleted 2 will return 2), said the number of rows affected is three lines, namely three rows are deleted, inserted, change is in the same way, returns 0, is not one of the line, the line is not to add to any deletion, but don't say ExecSQL failure, ExecSQL just submit a SQL statements, the SQL itself, that's right, operation failure may be other reasons, such as delete 3 jump record, including a record with constraints can't successful operation, CodePudding user response:
Realize the teacher, the answer, can meet the needs of the building Lord, CodePudding user response:
That if ExecSQL change into the Open and make qry2 ExecuteOptions:=[eoExecuteNoRecords];//query execution does not return to record the way, the EOleException class exception message 'parameter type is not correct, or are not within an acceptable range, or conflict with other parameters, return 1 what that refers to the parameter type is not correct, "is outside the scope of acceptable" or "conflict with other parameters? CodePudding user response:
Is ExeSQL, this function returns a value, the return value is the executing SQL affects the number of rows, CodePudding user response:
ExecSQL returns affect the number of records