Note: This is the Windows app, SQL Server, database as ado.net.
I insert images in the DataGrade view temporarily so loop through them and save each row in the database. I know how to insert a stream from a photo box like this
MemoryStream Stream = new memorystream (); PictureBox1.Image.Save (Stream, System .making imaging.format.jpg); Byte [] pic = stream.ToArray (); SQL Commands CMDA = Include new SQL Commands ("Key word (item name, dateinterity, image, image index) values (n '" + listbox. I.ToString () + "', GETDATE (), @image, 1) , CN); Cmda.Parameters.AddWithValue ("@ Pic", photo); Try {Cn.Open (); Cmda.ExecuteNonQuery (); } Hold (Exception pre) {Message Box. Show (ex.Message); } Finally {cn.Close (); }
I want to change the pictureBox1
with dataGridView1.Rows [x]. Call [1]. Value
My question is how to save images from DataGride Viveste?
You can go like this:
image myImg = ( DataGridView1.Rows [x]. Cell [1]. Value as image); MyImg.Save (stream, system. Drawing imaging. Image format.jpg);
or in a line without the use of a variable:
(DataGrid view. Rows [x] .binger [1]. value). Save (stream, system, drawing .imaging format .jpg);
You know that the value of DataGridViewImageColumn
is image
hence the conversion is secure.
Comments
Post a Comment