我一直在试图找出如何提交pdf文件到mysql数据库通过我的vb.net项目,到目前为止,我只能找出如何插入到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
下面是在我的项目中的adobepdf阅读器上显示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
暂无答案!
目前还没有任何答案,快来回答吧!