if (image1.Image != null) image1.Image.Dispose(); SqlCommand cmd22 = new SqlCommand("Image_proc", cs); cmd22.CommandType = CommandType.StoredProcedure; cmd22.Parameters.Add("@imgId", SqlDbType.Int).Value = Convert.ToInt32(dgID.Text); SqlDataAdapter adp = new SqlDataAdapter(cmd22); DataTable dt = new DataTable(); try { if (cs.State == ConnectionState.Closed) cs.Open(); adp.Fill(dt); if (dt.Rows.Count > 0) { MemoryStream ms = new MemoryStream((byte[])dt.Rows[0]["Image"]); image1.Image = Bitmap.FromStream(ms); image1.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (cs.State == ConnectionState.Open) cs.Close(); }
if (dt.Rows.Count > 0) { object o = dt.Rows[0]["Image"]; Image im = null; if (o != DBNull.Value) { MemoryStream ms = new MemoryStream((byte[])o); im = Bitmap.FromStream(ms); } image1.Image = im; image1.Refresh(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)