因此,我正在尝试将一些图像上传功能添加到我正在编写的网络应用程序中,但遇到了一些问题。出于某种原因,每当我尝试执行图像保存功能时,图像都无法插入。
这是我的功能:
Public Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If fileupload1.HasFile Then
Dim pimage(fileupload1.PostedFile.ContentLength - 1) As Byte
pimage = fileupload1.FileBytes
Dim pid As String = partnum.Text.ToString
Dim sConnection As String = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=inteva; UID=root; PASSWORD=root; OPTION=3"
Dim connectme As New OdbcConnection(sConnection)
Dim sInsertInto As String = "INSERT INTO images(id_num, serial, image1) VALUES(LAST_INSERT_ID(), @pserial, @ppimage)"
Dim com As New OdbcCommand(sInsertInto, connectme)
com.Parameters.Add("@pserial", OdbcType.VarChar).Value = pid
com.Parameters.Add("@ppimage", OdbcType.VarBinary).Value = pimage
connectme.Open()
Dim result As Integer = com.ExecuteNonQuery()
connectme.Close()
If result > 0 Then
lblimageup.Text = "Image saved."
End If
Else
lblimageup.Text = "Please select an image file"
End If
End Sub
关于为什么图像没有插入的任何想法?