FDQuery 怎么能插入NULL参数

时间:2022-11-06 05:05:27

[FireDAC][Phys][MSSQL]-335. Parameter [fieldAA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call

以前BDE可以。

ADO

qrypub->ParamByName("fieldAA")->DataType= ftDateTime;

qrypub->ParamByName("fieldAA")->DataType= ftString;

DataType就是字段类型,设置字段类型就可以插入NULL值了,不赋值执行insert或update语句自动填充为NULL值了。

2016.9.23 record,

fdquery有个属性,FormatOptions.DefaultParamDataType=ftUnknow,默认是ftUnknown,改为ftString或者ftVariant也许就好了,未测试。

2017.5.11 测试用ftString是ok了。

qrypub->FormatOptions->DefaultParamDataType = ftString;

TFieldType : unsigned char { 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, ftFixedWideChar, ftWideMemo, ftOraTimeStamp, ftOraInterval, ftLongWord, ftShortint, ftByte, ftExtended, ftConnection, ftParams, ftStream, ftTimeStampOffset, ftObject, ftSingle };

TADTField
TAggregateField
TArrayField
TAutoIncField
TBCDField
TBinaryField
TBlobField
TBooleanField
TByteField
TBytesField
TCurrencyField
TDataSetField
TDateField
TDateTimeField
TExtendedField
TFloatField
TFMTBCDField
TGraphicField
TGuidField
TIDispatchField
TIntegerField
TInterfaceField
TLargeintField
TLongWordField
TMemoField
TNumericField
TObjectField
TReferenceField
TShortintField
TSingleField
TSmallintField
TSQLTimeStampField
TSQLTimeStampOffsetField
TStringField
TTimeField
TUnsignedAutoIncField
TVarBytesField
TVariantField
TWideMemoField
TWideStringField
TWordField

Param [PName] type changed from [ftString] to [ftFixedChar]. Query must be reprepared. Possible reason: an assignment to a TFDParam.AsXXX property implicitly changed the parameter data type. Hint: use the TFDParam.Value or appropriate TFDParam.AsXXX property.

ftFixedChar 对应的数据库字段类型是char

ftString 对应的数据库字段类型是varchar

所以修改数据库类型即可。