title: How to save and retrieve image in SQL Server 2008R2 using Asp.Net via VB.Net
body: <p>I have a FileUpload <code>fileupload2</code> control and an image box control <code>image1</code>. Now I want to save the browsing image and also show it on image box when I browsing the path. I am writing the code like below. </p>
  
  <p>What's the problem in that code and how I show it on image box when I browsing the path?</p>
  
  <pre><code>Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
      Connection()
  
      Dim cmd As New SqlCommand
      cmd.Connection = cn
      cmd.CommandText = "INSERT INTO Personal_info (image_id,pic)VALUES (@image_id,@pic)"
  
      cmd.Parameters.Add("@image_id", SqlDbType.VarChar, 200)
      cmd.Parameters.Add("@pic", SqlDbType.Image, 200)
  
      cmd.Parameters("@image_id").Value = txtid.Text
      cmd.Parameters("@pic").Value = FileUpload2.FileBytes
  
      Dim i = -1
  
      i = cmd.ExecuteNonQuery
  
      If i = -1 Then
          lblMessage.ForeColor = Drawing.Color.Red
          lblMessage.Text = "Fail to Save"
          'MsgBox("Fail", MsgBoxStyle.OkOnly, "Error")
      Else
          lblMessage.ForeColor = Drawing.Color.Green
          lblMessage.Text = "Success to Save"
      End If
  End Sub
  </code></pre>