Я хочу получить pdf файл формы SQL server в VB.NET
я хочу получить или загрузить Pdf-файл с sql server с помощью vb.net-да.
тот код который я собираюсь прикрепить используется для хранения pdf файла sql server
Что я уже пробовал:
Public Class Form5 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click OpenFileDialog1.InitialDirectory = "C:\" OpenFileDialog1.Title = "Open a PDF file" OpenFileDialog1.Filter = "PDF files|*.pdf" OpenFileDialog1.ShowDialog() TextBox1.Text = OpenFileDialog1.FileName End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click SavePDFtoDB() End Sub Private Sub SavePDFtoDB() Try Dim sqlconn As SqlConnection Dim conn As String = (Configuration.ConfigurationManager.AppSettings("ConnectionString").ToString()) sqlconn = New SqlConnection(conn) Dim sqlquery As New SqlCommand Dim fInfo As New FileInfo(TextBox1.Text) Dim numBytes As Long = fInfo.Length Dim fStream As New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read) Dim br As New BinaryReader(fStream) Dim data As Byte() = br.ReadBytes(CInt(numBytes)) br.Close() fStream.Close() 'Insert the details into the database sqlquery.Connection = sqlconn sqlconn.Open() sqlquery.CommandText = "INSERT INTO tbldocument(filename, extension, content)VALUES(@filename, @extension, @content)" sqlquery.Parameters.Add(New System.Data.SqlClient.SqlParameter("@filename", TextBox1.Text)) sqlquery.Parameters.Add(New System.Data.SqlClient.SqlParameter("@extension", ".pdf")) sqlquery.Parameters.Add(New System.Data.SqlClient.SqlParameter("@content", data)) sqlquery.ExecuteNonQuery() sqlconn.Close() MsgBox("Saved") Catch err As Exception MsgBox(err.Message) End Try End Sub End Class