Display OLE Object
-
Dear All, I used OLe Container in VB6.0 to upload image to database. The image is saved in database as compounded file binary. Now I am using VB.NET to retrieve the file.. but somehow I could not extract the embedded file from that OLE Binary. Does someone have a workaround for this? Much Appreciated. Sandy
-
Dear All, I used OLe Container in VB6.0 to upload image to database. The image is saved in database as compounded file binary. Now I am using VB.NET to retrieve the file.. but somehow I could not extract the embedded file from that OLE Binary. Does someone have a workaround for this? Much Appreciated. Sandy
This should work for you. I know that it works with MS-Access. Assuming you table contains the following fields IMAGE_ITEM_ID : Long NAME : Text IMAGE : OLE Object Public Sub GetItem(ByVal itemId As Long) Dim sqlQuery As String ' the query to execute Dim image() As Byte ' the image to get Dim name as String ' the name of the image sqlQuery = "SELECT IMAGE_ITEM_ID, NAME, IMAGE " & _ "FROM IMAGE_ITEM " &_ "WHERE IMAGE_ITEM_ID = " & itemId Try ' instanciate a connection object Dim conn As OleDb.OleDbConnection = GetConnection() ' instanciate a command object Dim com As New OleDbCommand(sqlQuery, conn) ' open the connection com.Connection.Open() ' create a read to read the database Dim reader As OleDbDataReader ' open the reader reader = com.ExecuteReader(CommandBehavior.CloseConnection) ' read the first record If (reader.Read()) Then ' get the name of the image name = reader.GetString(1) ' get the image itemData.Image = CType(reader.Item(2), Byte()) End If ' clean up after yourself reader.Close() com.Connection.Close() conn.Dispose() 'release memory to garbage collection com.Dispose() 'release memory to garbage collection Catch eOleDb As OleDb.OleDbException MsgBox("OleDb Error - GetItem - [" & eOleDb.Message & "]") End Try End Sub I hope it works for you.