Вниз
Скачать: CL | DM;

Invalid variant type conversion при работе с рекордсетом   Найти похожие ветки 

 
Sergeyy ©   (2002-07-17 09:12) [0]

на форме - ADOConnection1 с подключением к Ораклу по OLE DB

var
rst:_recordset;
VarRstResult: Variant;
sSQL: string;
CurRow, CurCol:Integer;
begin
CurRow := 0;
sSQL := "select...";
rst := ADOConnection1.Execute(sSQL);
VarRstResult := VarArrayCreate([1, rst.RecordCount, 1, rst.Fields.Count], varVariant);
while (not rst.EOF) and (CurRow < 65536) do
begin
CurRow := CurRow + 1;
for CurCol := 1 to rst.Fields.Count do
rstResult[CurRow, CurCol] := rst.Fields[CurCol - 1].Value;
rst.MoveNext;
Application.ProcessMessages;
end;
rst.Close;
end;


Этот код в D5 работает на "ура". В D6 - при присвоении значения поля рекордсета элементу массива - ошибка "Invalid Variant Type conversion". Эта ошибка возникает при попытке обработать числовое поле или поле с датой. Строковые поля идут без проблем.

Кто-нить знает, как преодолеть?


 
kig ©   (2002-07-17 10:56) [1]

А попробуйте этим воспользоваться

"
GetRows Method
Retrieves multiple records of a Recordset object into an array.

Syntax
array = recordset.GetRows( Rows, Start, Fields )
Return Value
Returns a Variant whose value is a two-dimensional array.

Parameters
Rows
Optional. A GetRowsOptionEnum value that indicates the number of records to retrieve. The default is adGetRowsRest.
Start
Optional. A String value or Variant that evaluates to the bookmark for the record from which the GetRows operation should begin. You can also use a BookmarkEnum value.
Fields
Optional. A Variant that represents a single field name or ordinal position, or an array of field names or ordinal position numbers. ADO returns only the data in these fields.
"

А потом сравните в полученном массиве, как числовое поле там представлено и в соответствующим Fields[xx].Value


 
German Ivanov   (2002-07-19 04:58) [2]

Скорее всего у тебя одно из полей содержит NULL

Вот пример для ADODB.Recordset обходящий эту ситуацию.

var
v:variant;
fldname:string;
begin

...

v:=fromrs.Fields[fldname].Value;
if not(varType(v) in [varNull,varEmpty]) then begin
tors.Fields[fldname].Value:=v;
end;

...



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.014 c
3-23895
Александр Рогань
2002-07-17 18:15
2002.08.08
Динамическая загрузка формы из файла !!!


14-24191
Lola
2002-07-12 13:29
2002.08.08
---|Ветка была без названия|---


1-24079
U-Rustam
2002-07-26 13:17
2002.08.08
Перевод из Delphi 3 в Delphi 5


3-23903
Crypto
2002-07-16 23:10
2002.08.08
Почему не создается lookup-поле в Query?


1-23986
Nostradamus
2002-07-26 23:48
2002.08.08
Интерестно




   Наверх