473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Problems with DB Image field upload

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"
Feb 22 '08 #1
0 1063

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Roger Withnell | last post by:
I'm updating a record by opening a recordset, setting the fields and the updating it with objRS.Update. I need to set an image datatype to NULL. objRS("field") = NULL works for datatypes int...
7
by: Showjumper | last post by:
Hi, I have developed an upload server controls to be reused over a number of projects. One of the tasks it needs to handle is to rotate an image. I want to accoplish this by checking the checkbox...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
6
by: Neo Geshel | last post by:
About 4 months ago I came across this one web page that talked about streaming raw image data (from a database, for example) directly to a web page without requiring a secondary ASPX page to...
4
by: jens Jensen | last post by:
Hello, I have an image file name in a table that a let users modify via a GridView/DetailView pair. * The actual image file is saved in the image folder of the application. But the image is...
7
tolkienarda
by: tolkienarda | last post by:
hi all I am using a php script to try to upload images to my database. i know i am connecting to my database because the image title is being wirtten to the database. but the image isn't example:...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
7
by: dragiton | last post by:
SA Upload SQL Database variable types (image upload and storage) I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.