private void btnSearch_Click(object sender, EventArgs e)
{
SqlConnection CN = new SqlConnection("Data Source=sakthi\\sqlexpress; Initial Catalog=LoginDetails; Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from emp where empcode ='" + txtEmpCode.Text + "'", CN);
SqlDataReader myreader;
DataTable dt = new DataTable();
MemoryStream ms = new MemoryStream();
try
{
CN.Open();
myreader = cmd.ExecuteReader();
if (myreader.Read())
{
txtEmpCode.Text = myreader[0].ToString();
txtName.Text = myreader[1].ToString();
txtGender.Text = myreader[3].ToString();
byte[] pic = (byte[])myreader[2];
ms = new MemoryStream(pic);
ms.Seek(0, SeekOrigin.Begin);
pictureBox1.Image = Image.FromStream(ms);
}
else
{
MessageBox.Show("do not found");
}
CN.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}

VulpesRank #55 · 29.2K reputationPosted Oct 15, 2013, 4:56 AM EDT
ms.Seek(0, SeekOrigin.Begin);
Sakthis50 reputationPosted Oct 15, 2013, 5:31 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 15, 2013, 6:09 AM EDT
pictureBox1.Image = Image.FromStream(ms);
then, on the face of it, the image is invalid.
So what kind of image is it and where did you obtain it from in the first place?
I'd also try inserting this line just before the one giving the error to make sure the stream looks to be of the right size:
MessageBox.Show(ms.Length.ToString());