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(s trConnection)
Dim workParam As New SqlParameter("@ IPicture", SqlDbType.Image )
'I put in a bytes array the uploaded file
Dim bufferLen As Integer =
Convert.ToInt32 (uploadedFile.P ostedFile.Input Stream.Length)
Dim buffer(bufferLe n) As Byte
uploadedFile.Po stedFile.InputS tream.Read(buff er, 0, bufferLen)
Try
cnn.Open()
workParam.Direc tion = ParameterDirect ion.Input
workParam.Size = bufferLen
workParam.Value = buffer
Dim sqlCommandInsUp d As New SqlCommand("SP_ INSERT", cnn)
sqlCommandInsUp d.CommandType = CommandType.Sto redProcedure
sqlCommandInsUp d.Parameters.Ad d(workParam)
sqlCommandInsUp d.ExecuteNonQue ry()
Catch exErr As System.Exceptio n
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 "binarywrit e"
function the image appears corrupted ...
------------------------- ADODB --------------------------
Dim cnn As New ADODB.Connectio n
Dim cmd As New ADODB.Command
Dim parm As ADODB.Parameter
Dim bufferLen As Integer =
Convert.ToInt32 (uploadedFile.P ostedFile.Input Stream.Length)
Dim buffer(bufferLe n) As Byte
uploadedFile.Po stedFile.InputS tream.Read(buff er, 0, bufferLen)
cnn.Open(strCon nection)
cmd.ActiveConne ction = cnn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "SP_INSERT"
parm = New ADODB.Parameter
parm.Name = "@IPicture"
parm.Type = ADODB.DataTypeE num.adLongVarBi nary
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"
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(s trConnection)
Dim workParam As New SqlParameter("@ IPicture", SqlDbType.Image )
'I put in a bytes array the uploaded file
Dim bufferLen As Integer =
Convert.ToInt32 (uploadedFile.P ostedFile.Input Stream.Length)
Dim buffer(bufferLe n) As Byte
uploadedFile.Po stedFile.InputS tream.Read(buff er, 0, bufferLen)
Try
cnn.Open()
workParam.Direc tion = ParameterDirect ion.Input
workParam.Size = bufferLen
workParam.Value = buffer
Dim sqlCommandInsUp d As New SqlCommand("SP_ INSERT", cnn)
sqlCommandInsUp d.CommandType = CommandType.Sto redProcedure
sqlCommandInsUp d.Parameters.Ad d(workParam)
sqlCommandInsUp d.ExecuteNonQue ry()
Catch exErr As System.Exceptio n
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 "binarywrit e"
function the image appears corrupted ...
------------------------- ADODB --------------------------
Dim cnn As New ADODB.Connectio n
Dim cmd As New ADODB.Command
Dim parm As ADODB.Parameter
Dim bufferLen As Integer =
Convert.ToInt32 (uploadedFile.P ostedFile.Input Stream.Length)
Dim buffer(bufferLe n) As Byte
uploadedFile.Po stedFile.InputS tream.Read(buff er, 0, bufferLen)
cnn.Open(strCon nection)
cmd.ActiveConne ction = cnn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "SP_INSERT"
parm = New ADODB.Parameter
parm.Name = "@IPicture"
parm.Type = ADODB.DataTypeE num.adLongVarBi nary
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"