Click here to Skip to main content
13,055,884 members (49,849 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone.
I am working on a project where user data is stored in sql db along with its image which is captured using a webcam.
I have finished the part where image is captured successfully and stored in picturebox, but the image from picturebox doesn't pass into the sql table, this part gives an error.

this is my code to insert picturebox image into sql database

Dim cmd As New SqlCommand("INSERT INTO detail4 VALUES(@tag,@pic)", sql)
cmd.Parameters.AddWithValue("@name", Button1.Text)
Dim ms As New MemoryStream()
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@photo", SqlDbType.Image)
p.Value = data
MessageBox.Show("Name & Image has been saved", "Save",MessageBoxButtons.OK)

i get an error at
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)

is it because of rawformat... pls help...
Posted 31-Mar-13 0:36am
ProgramFOX 31-Mar-13 6:42am
Which error do you get?
JPais 31-Mar-13 6:51am
"Value cannot be null. Parameter name: encoder" at
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


PictureBox1.BackgroundImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)

Hope this helps.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

When i insert image into sqldatabase using store procedure it gives an error at "PictureBox1.BackgroundImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)" error is
>Object reference not set to an instance of an object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 19 Feb 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100