ADOStoredProc 如何傳入參數 |
答題得分者是:hagar
|
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
參考:
一.傳入值
Using TADOStoredProc input parameters
Use an input parameter to supply a value to a stored procedure
before executing that stored procedure. Such values are typically
used in the WHERE clause of a stored procedure's SQL statement to
limit the number of table rows affected. Assign the parameter a
value before activating the TADOStoredProc by calling its Open
method or setting it Active property to True (for stored procedures
that return a result set) or before executing the TADOStoredProc
with its ExecProc method.
At design-time, access parameters through the Object Inspector.
With focus in the cell for the Parameters property, click the
ellipsis button. This invokes the parameters editor dialog. Enter
a value of the appropriate type in the Value property.
At runtime, assign a value to the Value property of the TParameter
component for the target parameter. Use the TParameter reference
provided by the Parameters property of the TADOStoredProc.
with ADOStoredProc1 do begin Close; Parameters[1].Value := 1; Open; end;二.回傳值 Using TADOStoredProc output parameters Use an input parameter to return a single value from a stored procedure. While a result set might consist of multiple rows of multiple columns, this output parameter must be the equivalent of one row containing one column. If the stored procedure uses a SELECT statement to retrieve this value, an attempt to return multiple values results in an exception. An output parameter only contains a value after the stored procedure has been activated or executed. Note that not all database systems support returning both a result set and output parameters. Check the documentation for the particular database system you are using to verify what it supports in this regard. If a database system supports both returning a result set and output parameter values, the TADOStoredProc can be activated using either its Open method (or Active property) or its ExecProc. If the database system does not support both, you can only use output parameters to retrieve values by calling the ExecProc method. At design-time, access parameters through the Object Inspector. With focus in the cell for the Parameters property, click the ellipsis button. This invokes the parameters editor dialog. If the TADOStoredProc is activated using its Active property (the only way to activate it at design-time), inspect the output parameter's Value property to see the value returned. At runtime, assign a value to the Value property of the TParameter component for the target parameter. Use the TParameter reference provided by the Parameters property of the TADOStoredProc. For example, the routine below returns a String value through the output parameter named @OutParam1. with ADOStoredProc1 do begin Close; ShowMessage(VarToStr(Parameters.ParamByName('@OutParam1').Value)); ExecProc; end;--- 每個人都是一本書 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |