i am performing search operation and retreiving image from database to pictureEdit control. I stored image as varchar(4000). and images are storing in the format of System.Drawing.Bitmap.I am getting Error as -> "Unable to cast object of type 'System.String' to type 'System.Byte[]".
- private void btnSearch_Click(object sender, EventArgs e)
- {
- byte[] getImg = new byte[0];
- SqlDataAdapter dataAdapter = new SqlDataAdapter("select sid,sname,fathername,contactno,address,sphoto from Student where sclass='" + lukupClass.Text + "' and ssection='" + lukupSection.Text + "' and sname='" + textBox1.Text + "'", sqlConnection);
- DataTable dt = new DataTable();
- dataAdapter.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- txtID.Text = dt.Rows[0]["sid"].ToString();
- txtStudentName.Text = dt.Rows[0]["sname"].ToString();
- txtFatherName.Text = dt.Rows[0]["fathername"].ToString();
- txtContactNo.Text = dt.Rows[0]["contactno"].ToString();
- memoAddress.Text = dt.Rows[0]["address"].ToString();
- getImg = ((byte[])dt.Rows[0]["sphoto"]);
- byte[] imgData = getImg;
- MemoryStream stream = new MemoryStream(imgData);
- picStudent.Image = Image.FromStream(new MemoryStream(getImg));
- }
- else
- {
- MessageBox.Show("No Data Found with this Name.");
- }