gpt4 book ai didi

mysql - vb.net上传pdf到mysql

转载 作者:行者123 更新时间:2023-11-29 18:03:28 25 4
gpt4 key购买 nike

所以我目前正在开发 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com