所以我试图在我正在编写的Web应用程序中添加一些图像上传功能,我遇到了一些问题。出于某种原因,只要我尝试执行图像保存功能,图像就无法插入。
这是我的功能:
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
关于图像未插入原因的任何想法?