所以我目前在vb.net上工作。我已经使用BLOB数据类型将图像上传到mysql。现在我需要将pdf文件上传到mysql。想知道图片上传代码是否与pdf相同。
这是我的图片上传代码。
'open file diaglog btn
Private Sub open_Click(sender As System.Object, e As System.EventArgs) Handles open.Click
Dim opf As New OpenFileDialog
opf.Filter = "Image File | *.jpg"
If opf.ShowDialog = DialogResult.OK Then
AxAcroPDF1.src = opf.FileName
text_file.Text = opf.SafeFileName
End If
End Sub
'save to my sql btn
Private Sub save_Click(sender As System.Object, e As System.EventArgs) Handles save.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=;database=printlmun"
Dim ms As New MemoryStream
PictureBox1.Image.Save(MS, PictureBox1.Image.RawFormat)
Dim command As New MySqlCommand("INSERT INTO `forms`(`name`, `price`, `img`) VALUES (@name,@text_price,@text_img)", MySqlConn)
command.Parameters.Add("@text_uname", MySqlDbType.VarChar).Value = text_uname.Text()
command.Parameters.Add("@text_price", MySqlDbType.VarChar).Value = text_price.Text
command.Parameters.Add("@text_img", MySqlDbType.Blob).Value = ms.ToArray()
MySqlConn.Open()
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("Image Inserted")
Else
MessageBox.Show("Image Not Inserted")
End If
MySqlConn.Close()
End Sub
最佳答案
BLOB代表二进制大对象。在这种情况下,文件类型无关紧要。与其图片,PDF,ZIP文件等无关。
是的,如果是图像或PDF(以字节数组表示),则代码是相同的。
关于mysql - vb.net将pdf上传到mysql,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48124857/