我有一个 FileUploadfileupload2
控件和一个图像框控件image1
。现在我想保存浏览图像并在浏览路径时将其显示在图像框上。我正在编写如下代码。
该代码有什么问题以及我在浏览路径时如何在图像框中显示它?
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