mysql - 使用 VB.NET 使用 BLOB 将 PDF 文件插入 MYSQL
问题描述
我一直在试图弄清楚如何通过我的 VB.NET 项目将 PDF 文件提交到 MYSQL 数据库中,到目前为止,我只能弄清楚如何将图像文件插入到 MYSQL 中,但我不确定如何翻译此代码支持 PDF 文件而不是图像。下面的代码显示了如何浏览图像并显示它。
Try
Dim OFD As FileDialog = New OpenFileDialog()
OFD.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif"
If OFD.ShowDialog() = DialogResult.OK Then
imgpath = OFD.FileName
PictureBox1.ImageLocation = imgpath
End If
OFD = Nothing
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
下面的代码显示了在选择图像后将图像文件插入到 MYSQL 数据库中。
Try
Dim mstream As New System.IO.MemoryStream()
PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
arrImage = mstream.GetBuffer()
Dim FileSize As UInt32
FileSize = mstream.Length
mstream.Close()
conn.ConnectionString = Myconnection
conn.Open()
sql = "insert into studentsubmissions(content, submissionid, studentnumber, time, date, deadline, title, work, modulename) VALUES (@filestuff, @subid, @stunumber, @subtime, @subdate, @workdeadline, @stutitle, @stuwork, @workmodulename)"
cmd.Connection = conn
cmd.CommandText = sql
cmd.Parameters.AddWithValue("@filestuff", arrImage)
cmd.Parameters.AddWithValue("@subid", idbox.Text)
cmd.Parameters.AddWithValue("@stunumber", usernameconstant.Text)
cmd.Parameters.AddWithValue("@subtime", todaystime.Text)
cmd.Parameters.AddWithValue("@subdate", todaysdate.Text)
cmd.Parameters.AddWithValue("@workdeadline", deadlinesubmission.Text)
cmd.Parameters.AddWithValue("@stutitle", titlesubmission.Text)
cmd.Parameters.AddWithValue("@stuwork", workload.Text)
cmd.Parameters.AddWithValue("@workmodulename", modulename.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Created")
cmd.Parameters.Clear()
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
下面是在我的项目中的 Adobe PDF Reader 上显示 PDF 文件的方法,这是我最终想要替换显示文档的第一组代码并使显示的第二组代码支持这一点的方法。
Dim opf As New OpenFileDialog
opf.Filter = "PDF File | *.pdf"
If opf.ShowDialog = DialogResult.OK Then
AxAcroPDF1.src = opf.FileName
text_file.Text = opf.SafeFileName
End If
解决方案
推荐阅读
- c# - 用于更快执行的 Lambda 表达式查询
- c# - 网站上的 PHP 攻击
- abap - RFC 导入/导出参数中的字符串和嵌套结构
- java - 总和存储在哪里?
- java - 如何为在一个模拟器中作为 RandomWaypoint 移动运行的节点组设置不同的区域
- django - 如何获取当前用户的 slug?
- javascript - 我可以在渲染时使用捆绑的 Javascript 文件操作 popup.html DOM 吗?
- python - 使用烧瓶中sqlalchemy的create_engine创建的引擎连接()时出现内存错误
- asp.net-mvc - 为什么 .NET Core Web API 调用 AddMVC() 和 UseMVC()?
- jquery - 如何仅显示最近的 i 元素?