是用ADO连接SQL SERVER吗?我以前也遇到这样的问题,这个问题是由于delphi的bug引起的,但可以通过修改delphi源码修复的。unit ADODB; ......function VarDataSize(const Value: OleVariant): Integer; begin if VarIsNull(Value) then Result := -1 else if VarIsArray(Value) then Result := VarArrayHighBound(Value, 1) + 1 else if TVarData(Value).VType = varOleStr then begin Result := Length(PWideString(@TVarData(Value).VOleStr)^); if Result = 0 then Result := -1; end else Result := SizeOf(OleVariant); end;//修改的 function VarDataSize2(const Value: OleVariant): Integer; begin if VarIsNull(Value) then Result := -1 else if VarIsArray(Value) then Result := VarArrayHighBound(Value, 1) + 1 else if TVarData(Value).VType = varOleStr then begin Result := Length(VarToStr(Value)); if Result = 0 then Result := 1; end else Result := SizeOf(OleVariant); end;procedure TParameter.SetValue(const Value: Variant); const SizedDataTypes = [ftUnknown, ftString, ftFixedChar, ftWideString, ftMemo, ftBlob, ftBytes, ftVarBytes]; var NewSize: Integer; NewValue: OleVariant; begin if VarIsClear(Value) or VarIsNull(Value) then NewValue := Null else begin if DataType = ftUnknown then SetDataType(VarTypeToDataType(VarType(Value))); { Convert blob data stored in AnsiStrings into variant arrays first } if (DataType = ftBlob) and (VarType(Value) = varString) then NewValue := StringToVarArray(Value) else NewValue := Value; end; if DataType in SizedDataTypes then begin // NewSize := VarDataSize(NewValue); NewSize := VarDataSize2(NewValue);//以新算法,计算大小 if (Size = 0) or (NewSize > Size) then Size := NewSize; end; ParameterObject.Value := NewValue; end;
要么就是 ansi 与 wide string 没弄好
......function VarDataSize(const Value: OleVariant): Integer;
begin
if VarIsNull(Value) then
Result := -1
else if VarIsArray(Value) then
Result := VarArrayHighBound(Value, 1) + 1
else if TVarData(Value).VType = varOleStr then
begin
Result := Length(PWideString(@TVarData(Value).VOleStr)^);
if Result = 0 then Result := -1;
end
else
Result := SizeOf(OleVariant);
end;//修改的
function VarDataSize2(const Value: OleVariant): Integer;
begin
if VarIsNull(Value) then
Result := -1
else if VarIsArray(Value) then
Result := VarArrayHighBound(Value, 1) + 1
else if TVarData(Value).VType = varOleStr then
begin
Result := Length(VarToStr(Value));
if Result = 0 then Result := 1;
end
else
Result := SizeOf(OleVariant);
end;procedure TParameter.SetValue(const Value: Variant);
const
SizedDataTypes = [ftUnknown, ftString, ftFixedChar, ftWideString, ftMemo,
ftBlob, ftBytes, ftVarBytes];
var
NewSize: Integer;
NewValue: OleVariant;
begin
if VarIsClear(Value) or VarIsNull(Value) then
NewValue := Null
else
begin
if DataType = ftUnknown then
SetDataType(VarTypeToDataType(VarType(Value)));
{ Convert blob data stored in AnsiStrings into variant arrays first }
if (DataType = ftBlob) and (VarType(Value) = varString) then
NewValue := StringToVarArray(Value) else
NewValue := Value;
end;
if DataType in SizedDataTypes then
begin
// NewSize := VarDataSize(NewValue);
NewSize := VarDataSize2(NewValue);//以新算法,计算大小
if (Size = 0) or (NewSize > Size) then
Size := NewSize;
end;
ParameterObject.Value := NewValue;
end;