473,320 Members | 1,987 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,320 software developers and data experts.

how image from Picturebox is stored into sql

198 100+
Hi
i want to save image from picturebox into sql but i got the error 'ARTHEMATIC OPERATIONS RESULTED IN AN OVERFLOW' On line
bytBLOBData = New Byte() {ms.Length}

here is my code
sqlConnection = New SqlClient.SqlConnection(sConnectionString)
sqlCommand = New SqlClient.SqlCommand("INSERT INTO BLOBTest (BLOBData) VALUES (@BLOBData)", sqlConnection)

'//Save image from PictureBox into MemoryStream object.
ms = New MemoryStream()
PictureBox1.Image.Save(ms, ImageFormat.Jpeg)

'//Read from MemoryStream into Byte array.
bytBLOBData = New Byte() {ms.Length} // ERROR IS HERE
ms.Position = 0
ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length))

'//Create parameter for insert statement that contains image.
prm = New SqlClient.SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, False, 0, 0, "BLOBData", DataRowVersion.Current, bytBLOBData)

sqlCommand.Parameters.Add(prm)
sqlConnection.Open()
sqlCommand.ExecuteNonQuery()
sqlConnection.Close()

PLEASE GIVE ME SOME SOLUTION
VARINDER
Sep 23 '08 #1
1 2132
hi,
The Soln is Below , it's Working Fine..
Dim msImage As New MemoryStream
Dim strSQL As String
Dim Cn As New SqlConnection(STR_CURRENT_CONNECTION_STRING)
Dim cmd As SqlCommand

Try
If Not (imgStyle.Image Is Nothing) Then
imgStyle.Image.Save(msImage, imgStyle.Image.RawFormat)
Dim arrImage() As Byte = msImage.GetBuffer

' Close the stream object to release the resource.
msImage.Close()
strSQL = "INSERT INTO tableName (imgDesign)" _
& " VALUES (@Picture)"

'' A SqlCommand object is used to execute the SQL statement.
cmd = New SqlCommand(strSQL, Cn)
With cmd
.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrImage
End With

Try it out.......
bye
Ganesh
Sep 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: CroDude | last post by:
Hi all! I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control. In a thumbnail mouse down event I'm using...
1
by: marco | last post by:
I'm a newbie and i'm doing a little application that open image. I don't understand what i've to do to have a zoom of an image...i don't know where's the error. If anyone know a simple code tell me...
2
by: marco | last post by:
I'm a newbie and i'm doing a little application in C# for a Pocket PC that open image. I don't understand what i've to do to have a zoom of an image...i don't know where's the error. If anyone...
6
by: Luis Arvayo | last post by:
Hello, I am trying to convert a jpeg image stored in a PictureBox to a byte array in order to later save it to a database, but I get this error : "Generic Error in GDI+". The source code is...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
4
by: John Swan | last post by:
Hello. I'm trying to create a simple program that amongst other things creates a thumbnail of an image (Bitmap) to a set size determined by the user in pixels? The problem is: All of the...
1
by: Joe Spears | last post by:
Hi Is there a simple way to bind a PictureBox image to a datatable?? I've tried pictureBox.DataBindings.Add("BackgroundImage", dt1, "Picture"); But it doesn't seem to work. Do I have to go...
7
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g....
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.