title: Picture box to byte array
body: <p>I have a program to select an image and to set that selected image in a picture box then convert the image in the image box to byte array and save sql server data base in a image type column.</p>
  
  <p>In browse button click event I'm selecting the image file like this.</p>
  
  <pre><code>OpenFileDialog fop = new OpenFileDialog();
  fop.InitialDirectory = @"Desktop";
  fop.Filter = "image files|*.jpg;*.png;*.gif";
  if (fop.ShowDialog() == DialogResult.OK)
  {
       FileStream FS = new FileStream(@fop.FileName, FileMode.Open, FileAccess.Read);  
       pbPartySymbol.Image = new Bitmap(fop.FileName);
       MessageBox.Show("Image Imported Successfully!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  }
  </code></pre>
  
  <p>After selecting the image and setting it the picture box image I'm converting the picture box image to byte array in the save button click event and saving the byte array to database.</p>
  
  <pre><code>public byte[] imageToByteArray(System.Drawing.Image imageIn)
  {
      MemoryStream ms = new MemoryStream();
      imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
      return ms.ToArray();
  }
  </code></pre>
  
  <p>I'm calling the method like this.</p>
  
  <pre><code>byte[] myArr1 = imageToByteArray(pbPartySymbol.Image);
  </code></pre>
  
  <p>and I'm passing this byte array to the data base. and it saves too. But <em>ALL</em> the added images are saved as like this.* 0x53797374656D2E427974655B5D* Saved images cannot be get back to the picture box in the reading operation. What am I doing wrong in the <em>SAVING</em>?  </p>
  
  <p>Here's what I do in saving operation in the form.</p>
  
  <pre><code>            Party ptObj = new Party(myArr1);
              if (new PartyOP().saveParty(ptObj))
              {
                  MessageBox.Show("NEW data added");
              }
  </code></pre>
  
  <p>In my business operation layer this is my code. </p>
  
  <pre><code>          public Boolean saveParty(Party ptObj)
           {
            string query1 = "EXEC insertToParty'" + ptObj.PTSymARR + "'";
             return (new DataAccessLayer().executeNonQueries(query1));
          }
  </code></pre>
  
  <p>Here's how I have set the property in the Party class.</p>
  
  <pre><code>class Party
  {
      public Party() { }
      public Party(byte[] ptSym) 
      {
  
          this._PTSymARR = ptSym;
  
      }
      public byte[] PTSymARR
      {
          get { return _PTSymARR; }
          set { _PTSymARR = value; }
      }
  
  
  }
  </code></pre>
  
  <p>here's my stored procedure.
        CREATE PROCEDURE insertToParty
     (
        @ptSymbol image
    )
      AS 
      BEGIN
      BEGIN TRANSACTION 
      SET NOCOUNT ON;
        --Query
      INSERT INTO Party(PTSYM) 
         VALUES (@ptSymbol);</p>
  
  <p>Data type of PTSYM is image data type. </p>