I have facing with datatable with connection. I don't want to use sqlconnection in the code and using with external class. Please help me. How do I get the photo from the database and convert binary to image. Thanks in advance.
private void btnselect_Click(object sender, EventArgs e)
{
if (picemployee.Image != null)
{
picemployee.Image.Dispose();
}
try
{
EmpPhoto objEmpPhoto = new EmpPhoto();
objEmpPhoto.EmployeeID = txtemployeeid.Text;
objEmpPhoto.GetSingleEmpPhoto();
//EmpPhoto.GetSingleEmpPhoto();
SqlDataAdapter myAdapter1 = new SqlDataAdapter();
DataTable dt = EmpPhoto.dtEmpPhoto;
myAdapter1.Fill(dt);
try
{
if (dt.Tables[0].Rows.Count > 0)
{
if (dt.Tables[0].Rows[0][0] != System.DBNull.Value)
{
byte[] photo_aray = (byte[])dt.Tables[0].Rows[0][0];
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
Image img = (Image)converter.ConvertFrom(photo_aray);
pictureBox1.Image = img;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Refresh();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}