problem in insert picture to sql
-
I use below code for add picture to dataBase but if I need that insert null instead of picture into database the program give me Error (I set allowNull for column in Sql) (it's neccesary becuase maybe user dosen't have picture for insert into database) how can I do that? MemoryStream mstr = new MemoryStream(); pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat); byte[]pic= mstr.GetBuffer(); SqlConnection sq=new SqlConnection(...); SqlParameter sp1 = new SqlParameter("@pic", pic); SqlCommand sc = new SqlCommand("insert into Info values(@pic)", sq); sc.Parameters.Add(sp1); sc.ExecuteNonQuery();
-
I use below code for add picture to dataBase but if I need that insert null instead of picture into database the program give me Error (I set allowNull for column in Sql) (it's neccesary becuase maybe user dosen't have picture for insert into database) how can I do that? MemoryStream mstr = new MemoryStream(); pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat); byte[]pic= mstr.GetBuffer(); SqlConnection sq=new SqlConnection(...); SqlParameter sp1 = new SqlParameter("@pic", pic); SqlCommand sc = new SqlCommand("insert into Info values(@pic)", sq); sc.Parameters.Add(sp1); sc.ExecuteNonQuery();
Hi, could you post the error you receive (message etc.)? Maybe your db-schema doesn't allow null-values for the picture column. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hi, could you post the error you receive (message etc.)? Maybe your db-schema doesn't allow null-values for the picture column. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
I set allowNull for that column
-
I set allowNull for that column
And the error you receive is?
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
And the error you receive is?
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
Error : parameter @pic, which was not supplied
-
Error : parameter @pic, which was not supplied
Try to pass
System.DBNull.Value
as parameter value when pic1 is null.It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Try to pass
System.DBNull.Value
as parameter value when pic1 is null.It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
Error : Operand type clash: nvarchar is incompatible with image
-
Error : Operand type clash: nvarchar is incompatible with image
There's your problem right there. nvarchar is a text based field, and you are trying to store an image in it - you need to change the column type in the database, or save the image to disk and store the location of the image in this field.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
I use below code for add picture to dataBase but if I need that insert null instead of picture into database the program give me Error (I set allowNull for column in Sql) (it's neccesary becuase maybe user dosen't have picture for insert into database) how can I do that? MemoryStream mstr = new MemoryStream(); pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat); byte[]pic= mstr.GetBuffer(); SqlConnection sq=new SqlConnection(...); SqlParameter sp1 = new SqlParameter("@pic", pic); SqlCommand sc = new SqlCommand("insert into Info values(@pic)", sq); sc.Parameters.Add(sp1); sc.ExecuteNonQuery();
hi, try the following code, it may help you. int len = Upload.PostedFile.ContentLength; byte[] pic = new byte[len]; Upload.PostedFile.InputStream.Read (pic, 0, len); SqlConnection sq=new SqlConnection(...); SqlCommand cmd = new SqlCommand ("insert into values(@pic)", sq); cmd.Parameters.Add ("@pic", pic); cmd.ExecuteNonQuery ();
-
I use below code for add picture to dataBase but if I need that insert null instead of picture into database the program give me Error (I set allowNull for column in Sql) (it's neccesary becuase maybe user dosen't have picture for insert into database) how can I do that? MemoryStream mstr = new MemoryStream(); pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat); byte[]pic= mstr.GetBuffer(); SqlConnection sq=new SqlConnection(...); SqlParameter sp1 = new SqlParameter("@pic", pic); SqlCommand sc = new SqlCommand("insert into Info values(@pic)", sq); sc.Parameters.Add(sp1); sc.ExecuteNonQuery();
hi, try the following code, it may help you. int len = Upload.PostedFile.ContentLength; byte[] pic = new byte[len]; Upload.PostedFile.InputStream.Read (pic, 0, len); SqlConnection sq=new SqlConnection(...); SqlCommand cmd = new SqlCommand ("insert into values(@pic)", sq); cmd.Parameters.Add ("@pic", pic); cmd.ExecuteNonQuery ();
April Comm100 - Leading Live Chat Software Provider