I have a Picture box. The image in the picture box is a static one. I am loading the image from the resources folder. I am not able to read the static image from the picture box and store it in the database. here is my code.
private void btnOk_Click(object sender, EventArgs e)
{
Image votingBackgroundImage = pictureBox5.Image;
Bitmap votingBackgroundBitmap = new Bitmap(votingBackgroundImage);
Image votingImage = (Image)votingBackgroundBitmap;
var maxheight = (votingImage.Height * 3) + 2;
var maxwidth = votingImage.Width * 2;
if (maxheight == 227 && maxwidth == 720)
{
System.IO.MemoryStream defaultImageStream = new System.IO.MemoryStream();
Bitmap NewImage =new Bitmap(votingImage,new Size(720,227));
Image b = (Image)NewImage;
b.Save(defaultImageStream, System.Drawing.Imaging.ImageFormat.Bmp);
defaultImageData = new byte[defaultImageStream.Length];
}
}
Query I used to add the image in the database:
String MyString1=string.format("insert into question_table(background_image) Values(@background_image)");
com = new SqlCommand(MyString1, myConnection);
com.Parameters.Add("@background_image", SqlDbType.Image).Value = defaultImageData;
com.ExecuteNonQuery();
When I check this in the sql database.It stores the value as 0 x000000…
You are just creating the
byte[]but you never actually copied the contenttry