Delphi TADOStoredProc [2] Parameters 介绍
{该文首发于博客园 滔Roy,无须授权即可转载,请自觉保留头部申明}
Delphi TADOStoredProc [2] Parameters 介绍
1、常用参数:
- Clear //清空
- Refresh //初始化参数
- ParamByName //传递参数值
- CreateParameter //创建参数值
- ParamValues[]
- AddParameter
- FindParam
- Command
- Items[]
- Count
2、主要使用参数介绍
2.1 ParamByName
原型:
1 2 3 4 5 6 7 8 9 10 11 12 13 | function TParameters . ParamByName( const Value: WideString ): TParameter; function GetComponent: TComponent; begin Result := GetCommand; if Assigned(Result) and (Result . Owner is TCustomADODataSet) then Result := Command . Owner; end ; begin Result := FindParam(Value); if Result = nil then DatabaseErrorFmt(SParameterNotFound, [Value], GetComponent); end ; |
使用示例:
1 2 | Parameters . ParamByName( '@aa1' ).Value:= 1 ; //传递数值 Parameters . ParamByName( '@aa1' ).Value:= '你好' ; //传递文本 |
2.2 CreateParameter
原型:
1 2 3 4 5 6 7 8 9 10 11 | function TParameters . CreateParameter( const Name: WideString ; DataType: TDataType; Direction: TParameterDirection; Size: Integer ; Value: OleVariant): TParameter; begin Result := AddParameter; Result . FParameter := Create_Parameter(Name, DataType, Direction, Size); { Don't try to assign value when it is an EmptyParam (used when optional) } if not ((TVarData(Value).VType = varError) and (TVarData(EmptyParam).VError = $80020004 )) then Result . FParameter . Value := Value; end ; |
主要参数介绍:
TDataType = TFieldType:
- ftUnknown,
- ftString,
- ftSmallint,
- ftInteger,
- ftWord,
- ftBoolean,
- ftFloat,
- ftCurrency,
- ftBCD,
- ftDate,
- ftTime,
- ftDateTime,
- ftBytes,
- ftVarBytes,
- ftAutoInc,
- ftBlob,
- ftMemo,
- ftGraphic,
- ftFmtMemo,
- ftParadoxOle,
- ftDBaseOle,
- ftTypedBinary,
- ftCursor,
- ftFixedChar,
- ftWideString,
- ftLargeint,
- ftADT,
- ftArray,
- ftReference,
- ftDataSet,
- ftOraBlob,
- ftOraClob,
- ftVariant,
- ftInterface,
- ftIDispatch,
- ftGuid,
- ftTimeStamp,
- ftFMTBcd
TParameterDirection:
- pdUnknown,
- pdInput,
- pdOutput,
- pdInputOutput,
- pdReturnValue
Delphi 使用示例:
1 2 3 4 5 6 7 8 9 | with ADOStoredProc1 do begin Close; ProcedureName:= '存储过程' ; //存储过程名称 Parameters . Clear; //清空参数 ,然后下面开始创建参数 Parameters . CreateParameter( '@a1' ,ftInteger,pdInput, 20 , 1 ); Parameters . CreateParameter( '@a2' ,ftString,pdInput, 50 , '你好' ); Open; //返回结果集 end ; |
其他内容,有时间会补充 -- 2020.09.16
创建时间:2020.09.16 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!
分类:
Delphi 控N-ADO类
标签:
Delphi
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报