错误是正确的,但不是代码中的唯一错误。将您的代码更改为
ADOQuery1.Parameters.ParamByName('@nom_util').Value := 'John Smith';
(这=可能只是一个错字,在德尔福的 Pascal 中,赋值运算符是:=,而不是=。)
Ado 参数没有AsStringorAsValue属性。它们是 type TParameter,在 AdoDB.Pas 中定义为
TParameter = class(TCollectionItem)
[...]
public
procedure Assign(Source: TPersistent); override;
procedure AppendChunk(Val: OleVariant);
procedure LoadFromFile(const FileName: string; DataType: TDataType);
procedure LoadFromStream(Stream: TStream; DataType: TDataType);
property ParameterObject: _Parameter read GetParameter;
property Parameters: TParameters read GetParameters;
property Properties: Properties read GetProperties;
published
property Name: WideString read GetName write SetName;
property Attributes: TParameterAttributes read GetAttributes write SetAttributes default [];
property DataType: TDataType read GetDataType write SetDataType default ftUnknown;
property Direction: TParameterDirection read GetParameterDirection write SetParameterDirection default pdInput;
property NumericScale: Byte read GetNumericScale write SetNumericScale default 0;
property Precision: Byte read GetPrecision write SetPrecision default 0;
property Size: Integer read GetSize write SetSize default 0;
property Value: Variant read GetValue write SetValue;
end;
更新我可以从您的评论中看出存在一定程度的混淆。也许这会有所帮助:
假设您有一个带有 AName 字段的 Names 表,并且您想在 AName 字段中查找值为“Me”的行。
以下代码将执行此操作:
AdoConnection1.Connected := True;
AdoQuery1.SQL.Text := 'select * from [Names] where AName = :AName';
AdoQuery1.Parameters.ParamByName('AName').Value := 'Me';
AdoQuery1.Open;
在 SQL.Text 中,:AName只是查询中参数的占位符。约定是 ':' 后面的文本是表列的名称,但不一定是,任何有效的 Sql 名称都可以,如
AdoQuery1.SQL.Text := 'select * from [Names] where AName = :Something';
AdoQuery1.Parameters.ParamByName('Something').Value := 'Me';