Board index » delphi » TADOTable.Post throws "Row cannot be located for updating"
T 55
![]() Delphi Developer |
TADOTable.Post throws "Row cannot be located for updating"2007-03-01 06:32:13 PM delphi185 I am trying to store binary data in a BLOB field on a MySQL datasource. These MySQL blobs appear as TVarBytesField, and not as TBlobField in VCL. I connect to the datasource using MyODBC 3.51. The data I want to store is passed to a procedure in a stream. Below is the code, written in Delphi 7. What happens is that the call adoTbl.Post throws the exception EOleException : "Row cannot be located for updating. Some values may have been changed since it was last read.". I have tried setting CursorType to dtDynamic, but that doesn't make any difference. Any clue what might be wrong? If there is a much better scheme for achieving what I want to do, I am of course interested as well. Cheers, Guy procedure SetBinaryValue(nRecID: Integer; pStream: TStream); type // Upper bound not relevant LTCharArr = array [0 .. 2] of Char; var adoTbl: TADOTable; fld: TField; buffer: ^ LTCharArr; sze: Integer; pw: ^ Word; begin adoTbl := TADOTable.Create(Application); with adoTbl do begin TableName := 'Tbl_Test'; // Actual names in ConnectionString replaced by dummies for posting in public newsgroup ConnectionString := 'Driver={mySQL ODBC 3.51 Driver};Server=XXX;Port=3306;Database=YYY;UID=ZZZ;Pwd=PPP;'; try Open; // Fld_ID is an integer field set as primary key if Locate('Fld_ID', nRecID, []) then begin // Fld_BinData is a MySQL BLOB field fld := FieldByName('Fld_BinData'); Edit; if fld is TVarBytesField then begin try if (pStream = nil) or (pStream.Size = 0) then sze := 2 else sze := pStream.Size + 2; GetMem(buffer, sze); ZeroMemory(buffer, sze); pw := Pointer(buffer); // First 2 bytes of TVarBytesField data contain data length pw ^ := sze - 2; if sze>2 then pStream.Read(buffer[2], sze - 2); fld.SetData(buffer); FreeMem(buffer, sze) finally adoTbl.Post end end end finally Close end end; adoTbl.Free end { SetBinaryValue }; |