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); }
}
VulpesPosted Oct 15, 2013, 10:09 AM
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());
SakthisPosted Oct 15, 2013, 9:31 AM
VulpesPosted Oct 15, 2013, 8:56 AM
ms.Seek(0, SeekOrigin.Begin);