title: Displaying image from db to picturebox winforms c#
body: <p>Iam doing a winforms application to insert an image to a database(sql server 2008)and retrieve an image from database into a picture box.The code for inserting works perfectly.While the code for retrieving show's up an error parameter not Valid.I was trying various solutions found by goggling  but none of them succeeded.</p>
  
  <p>Here is my code for retrieving</p>
  
  <pre><code>           private void button2_Click(object sender, EventArgs e)
              {
   FileStream fs1 = new FileStream("D:\\4usdata.txt", FileMode.OpenOrCreate,FileAccess.Read);
          StreamReader reader = new StreamReader(fs1);
          string id = reader.ReadToEnd();
          reader.Close();
          int ide = int.Parse(id);
          con.Open();
          SqlCommand cmd = new SqlCommand("select img from tempdb where id='" + id + "'", con);
          //cmd.CommandType = CommandType.Text;
          //object ima = cmd.ExecuteScalar();
          //Stream str = new MemoryStream((byte[])ima);
          //pictureBox1.Image = Bitmap.FromStream(str);
          SqlDataAdapter dp = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          dp.Fill(ds);
          int c = ds.Tables[0].Rows.Count;
          if (c ==1)
          {
  
  
              Byte[] MyData = new byte[0];
              MyData = (Byte[])ds.Tables[0].Rows[0]["img"];
              MemoryStream stream = new MemoryStream(MyData);
              stream.Position = 0;
              pictureBox1.Image = Image.FromStream(stream);
  
          }
  
      }
  </code></pre>