Extract images through database

I am working on Extracting images from a database(SQL Server 2008)I im using a WPF application , using the Grid_Loaded event to load pages.The examples i have found are mainly using the combo box to select the ID of an image and displaying it. However i do not want to use the combo box.I have a few lines of code i have worked on and found on the internet, will be appreciated if someone helps me!\[code\]private void LoadImages() { try { string connstr = @"Server=CTGPJLPC21\SQLEXPRESS;Database=testing;Trusted_Connection=True;"; using (SqlConnection conn = new SqlConnection(connstr)) { conn.Open(); using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM test_table", conn)) { dset = new DataSet(); adapter.Fill(dset); } DataTable dt = dset.Tables[0]; foreach (DataRow row in dt.Rows) { if (dset.Tables[0].Rows.Count == 1) { byte[] data = http://stackoverflow.com/questions/15896413/(byte[])dset.Tables[0].Rows[0][0]; MemoryStream strm = new MemoryStream(); strm.Write(data, 0, data.Length); strm.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(strm); BitmapImage bi = new BitmapImage(); bi.BeginInit(); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); bi.StreamSource = ms; bi.EndInit(); myImg.Source = bi; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }\[/code\]
 
Top