How does delphi call SQL stored procedures and obtain results?
Adostoredproc1.close;
Adostoredproc1.procedurename: = 'SP _ thl ';
Adostoredproc1.parameters. Clear;
Adostoredproc1.parameters. createparameter ('out', ftinteger, pdoutput, 1, 1 );
Adostoredproc1.execproc;
Edit1.text: = adostoredproc1.parameters [0]. value;
Leftstr (), the Run Command System actually told me "Unrecognized identifier leftstr"
Add the strutils Unit
Simplest Stored Procedure
Database End
Create procedure aaa
@ WWW varchar (10) // Parameter
As
Select * from employees where pusercode = @ WWW
Go
Frontend Stored Procedure
Procedure tform1.button1click (Sender: tobject );
VaR outcount: integer;
Begin
Adostoredproc1.parameters. parambyname ('@ WWW'). Value: = '123 ';
Adostoredproc1.open;
// Adostoredproc1.execproc ;//
{Suppose you already have a stored procedure on the SQL server,
Then you and the program need an adoconnection to set the database connection,
Adostoredproc
After connection is connected to adoconnection
Producedure automatically displays the existing stored procedures in the database.
After the connection is set, you can see all the callable stored procedures in procedurename of adostoredproc.
, Select the storage process to use (according to the parameters, you can see the required parameters)
Program call code:
With adostoreproc1 do
Begin
Adostoredproc1.parameters. parambyname (''). Value: =;
Adostoredproc1.execproc;
End;
In the above example, no result set is returned during the storage process,
If a returned result set exists, open it using adostoredproc1.open}
// Showmessage (inttostr (adostoredproc1.parameters. parambyname ('@ outcount'). Value ));
End;
Stored Procedure with output parameters
Create procedure aaa
@ ABC char (10 ),
@ Mycount int output
As
Select @ mycount = count (*) from employees where pusercode = @ ABC
Return
Go
How to extract Parameters
Procedure tfrm_worker_info.button1click (Sender: tobject );
VaR outcount: integer;
Begin
Adostoredproc1.parameters. parambyname ('@ abc'). Value: = '123 ';
Adostoredproc1.execproc;
Showmessage (inttostr (adostoredproc1.parameters. parambyname ('@ mycount'). Value ));
End;