Subject SAving BLOB data
Author Nick Upson
(I've been asked this question but it's not my area, so forwarding it on)


I'm trying to save an image to a Firebird database. I'm using VB.net and
adodb. I can read the iamge from the database with no hassles. But when I try
write to the database I get errors. My database field is a BLOB of type
Binary.

I first convert the image to an array of bytes:
-----------------------------------------------------------------------------
---------------------------
Dim Ms As New System.IO.MemoryStream
Dim myParam1 As ADODB.Parameter
Dim myParam2 As ADODB.Parameter
picEmpPhoto.Image.Save(Ms, picEmpPhoto.Image.RawFormat)
' Dim arrayImage() As Byte = Ms.GetBuffer
Dim arrayImage() As Byte = Ms.ToArray
Ms.Close()
-----------------------------------------------------------------------------
---------------------------
Then I try write the array of bytes to the database....
-----------------------------------------------------------------------------
---------------------------
Dim rs As ADODB.Recordset = dbMan.getRecordSet
rs.Open("phototest", dbman.getConnection,
ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic,
ADODB.CommandTypeEnum.adCmdTable)
rs.AddNew()
rs.Fields("employeephoto").Value = arrayImage
rs.Update()
-----------------------------------------------------------------------------
---------------------------

When the line rs.Update executes the error generated is: "Multiple-step
operation generated errors. Check each status value."

I've also tried creating a Command Object and writing that the the database.
This doesn't work either:

-----------------------------------------------------------------------------
---------------------------
Dim dbCommand As New ADODB.Command
dbCommand.ActiveConnection = DBMan.getConnection
dbCommand.CommandType = ADODB.CommandTypeEnum.adCmdText
dbCommand.CommandText = "insert into phototest (employeephoto)
values (?)"
Dim dbParam As ADODB.Parameter
dbParam = dbCommand.CreateParameter("EmployeePhoto",
ADODB.DataTypeEnum.adLongVarBinary,
ADODB.ParameterDirectionEnum.adParamInput, arrayImage.Length, arrayImage)
dbCommand.Parameters.Append(dbParam)
dbCommand.Execute()
-----------------------------------------------------------------------------
---------------------------

The error here is "Type is Invalid."



--
Nick
-----We Solve your Computer Problems---
Founder & Listowner of the Prolifics User Group
Panther, Ingres, UNIX, Interbase, Firebird - Available Shortly