Hallo guyz! :-)
I've some problems when I try to perform a image upload into a SQL
Server 2000 DB Image field ...
I've tried both with the ADO.NET method and the ADODB method:
------------------------ ADO.NET ------------------------
Dim cnn As New SqlConnection(strConnection)
Dim workParam As New SqlParameter("@IPicture", SqlDbType.Image)
'I put in a bytes array the uploaded file
Dim bufferLen As Integer =
Convert.ToInt32(uploadedFile.PostedFile.InputStrea m.Length)
Dim buffer(bufferLen) As Byte
uploadedFile.PostedFile.InputStream.Read(buffer, 0, bufferLen)
Try
cnn.Open()
workParam.Direction = ParameterDirection.Input
workParam.Size = bufferLen
workParam.Value = buffer
Dim sqlCommandInsUpd As New SqlCommand("SP_INSERT", cnn)
sqlCommandInsUpd.CommandType = CommandType.StoredProcedure
sqlCommandInsUpd.Parameters.Add(workParam)
sqlCommandInsUpd.ExecuteNonQuery()
Catch exErr As System.Exception
Finally
cnn.Close()
cnn = Nothing
End Try
----------------------------------------------------------------
.... with this method I don't have errors but the bytestream writed in
the Db field is lightly different, so when I read the field with a
SELECT construct and I write out the image with the "binarywrite"
function the image appears corrupted ...
------------------------- ADODB --------------------------
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim parm As ADODB.Parameter
Dim bufferLen As Integer =
Convert.ToInt32(uploadedFile.PostedFile.InputStrea m.Length)
Dim buffer(bufferLen) As Byte
uploadedFile.PostedFile.InputStream.Read(buffer, 0, bufferLen)
cnn.Open(strConnection)
cmd.ActiveConnection = cnn
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.CommandText = "SP_INSERT"
parm = New ADODB.Parameter
parm.Name = "@IPicture"
parm.Type = ADODB.DataTypeEnum.adLongVarBinary
parm.Value = buffer
cmd.Parameters.Append(parm)
cmd.Execute()
parm = Nothing
cmd = Nothing
cnn.Close()
cnn = Nothing
----------------------------------------------------------------
.... on the "cmd.Parameters.Append(parm)" command an error occured:
"Parameter object is improperly defined. Inconsistent or incomplete
information was provided"