Importing Image from a non Navision table to a Navision blob field
May 12th, 2008ADO, Automations 2 CommentsIn SQL it is possible to define tables with a column, which is of type image. This field type is not known by Navision or by ADO and can thereby not be extracted like other fields.
There exists 2 ways to get this fields value.
1) One way is to stream the image to a file and then afterwards import it into the blob.
In this example I assume you already have the ADO Connection and thereby already got the ADORecordSet.
| | | copy code | | ? |
ADOStream.Type := 1; //1 = Binary |
ADOStream.Open; |
ADOStream.Write(ADORecordSet.Fields.Item(FieldName).Value); |
ADOStream.SaveToFile('c:\tmp.bmp',2); //2 = SaveCreateOverWrite |
ReturnTable.Picture.IMPORT('c:\tmp.bmp'); |
ADOStream.Close; |
CLEAR(ADOStream); |
Where ADOStream is 'Microsoft ActiveX Data Objects 2.8 Library'.Stream |
and ADORecordSet is 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset |
This method works for compressed and uncompressed Blob fields.
2) Another way is to move/insert the image into your table by using ADO RecordSet.
Create 2 connections, one to your image table (ADOConn) and one to the table in Navision (NAVconn) where you want the picture to be inserted. Then “transfer” the Value from one RecordSet to another and add it.
| | | copy code | | ? |
FromRecSet := ADOConn.Execute('SELECT image FROM tableX','',0); |
FromRecSet.MoveFirst; |
//The following query is used to get a "blank" recordset, just like a INIT in Navision |
MyQuery := 'SELECT [EntryNo], [Picture] FROM [MyTable] WHERE [EntryNo] = 0'; |
NewRecSet.Open(MyQuery,NAVconn,1,3,1); |
NewRecSet.AddNew; |
NewRecSet.Fields.Item('Picture').Value := FromRecSet.Fields.Item('image').Value; |
NewRecSet.Update; |
This method does not work for compressed Blob fields!
If you need to know more about ADO Connection or ADO RecordSet, then please read my previous posts on ADO.