save pdf into database

Discussions about PDF management.
Post Reply
rogaz
Posts: 1
Joined: Wed Apr 15, 2015 8:48 am

save pdf into database

Post by rogaz » Wed Apr 15, 2015 9:07 am

i hope someone can help me, how to save pdf into database, in code i'm used " picturebox" but i can change " picbox with gdviewer and thumbnail " how i can used the code for it..this is my code " button save image and load image " :(


private Sub Save_Image()
Dim conn As New OleDbConnection
Dim sConnString As String
Dim cmd As New OleDbCommand
Dim sSQL As String = String.Empty
Dim arrImage() As Byte
Dim Rogaz As New IO.MemoryStream
Dim bSaveImage As Boolean = False
Dim strImg As String = String.Empty

Try
If Not IsNothing(Me.PictureBox1.Image) Then
Me.PictureBox1.Image.Save(rogaz, Me.PictureBox1.Image.RawFormat)
arrImage = myMs.GetBuffer
bSaveImage = True
Else
arrImage = Nothing
bSaveImage = False
End If
If bSaveImage = True Then
If Microsoft.VisualBasic.Right(Application.StartupPath, 1) = "\" Then
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "SampleDB.accdb;Persist Security Info=False;"
Else
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SampleDB.accdb;Persist Security Info=False;"
End If
conn = New OleDbConnection(sConnString)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
If Me.txtDescription.Tag = 0 Then
cmd.CommandText = "INSERT INTO tbl_image ( image_description, [image] ) VALUES(@img_desc, @img)"
Else
cmd.CommandText = "UPDATE tbl_image set image_description = @img_desc, [image] = @img where id=@id"
End If
cmd.Parameters.Add("@img_desc", OleDbType.VarChar).Value = Me.txtDescription.Text
cmd.Parameters.Add("@img", OleDb.OleDbType.Binary).Value = arrImage
cmd.Parameters.Add("@id", OleDbType.BigInt).Value = Me.txtDescription.Tag
cmd.ExecuteNonQuery()
MsgBox("Image has been save.")
Else
MsgBox("Please add an image")
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try

End Sub


Private Sub Load_Image(ByVal iIMageID As Long)
Dim conn As New OleDbConnection
Dim sConnString As String
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Dim arrImage() As Byte
Dim rogaz As New IO.MemoryStream

Try
If Microsoft.VisualBasic.Right(Application.StartupPath, 1) = "\" Then
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "SampleDB.accdb;Persist Security Info=False;"
Else
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SampleDB.accdb;Persist Security Info=False;"
End If
conn = New OleDbConnection(sConnString)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, image_description as description, [image] from tbl_image where id= " & iIMageID

dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read
Me.txtDescription.Tag = dr("id")
Me.txtDescription.Text = CStr(dr("description"))
arrImage = CType(dr("image"), Byte())
For Each ar As Byte In arrImage
myMS.WriteByte(ar)
Next
'
Me.PictureBox1.Image = System.Drawing.Image.FromStream(myMS)
End While
End If

Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub

Private Sub Load_GridView()
Dim conn As New OleDbConnection
Dim sConnString As String
Dim cmd As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim dt As New DataTable

Try
If Microsoft.VisualBasic.Right(Application.StartupPath, 1) = "\" Then
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "SampleDB.accdb;Persist Security Info=False;"
Else
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SampleDB.accdb;Persist Security Info=False;"
End If
conn = New OleDbConnection(sConnString)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, image_description as description from tbl_image"
da.SelectCommand = cmd
da.Fill(dt)
Me.DataGridView1.DataSource = dt
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub


Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
Load_Image(CLng(Me.DataGridView1.Item(0, Me.DataGridView1.CurrentRow.Index).Value))
End Sub
End Class

thanx for the sollution gdpicture...best regards

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: save pdf into database

Post by Cedric » Mon Jun 08, 2015 10:28 am

Hello,

I'm sorry but we do not clearly understand what the issue is, you are talking about PDF but I see nothing about it in your code no more than GdPicture usage.
For database saving you definitely need to consider saving your documents as stream (images or PDF, the same applies for both) using the corresponding methods described in online the documentation.

Regards,
Cedric

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest