store and open pdf file to datagidview

store and open  pdf file to datagridview 

Use the following code to save images to the database with the save button, save well, delete images and delete well

what I want Save any file to the access database2007 - and reopen the file


'connection code 
'Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\Database1.accdb;Jet OLEDB:Database Password=2240")    'Dim DataSet1 As New DataSet   ' Dim BindingSource1 As BindingSource    'Dim BindingSource2 As BindingSource   ' Dim DataAdapter1 As New OleDbDataAdapter
Private Sub savimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savimage.Click ' save If BindingSource1.Count = 0 Then Beep() : Exit Sub Try If PictureBox1.Image IsNot Nothing Then If MsgBox(" change image " & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "استبدال صورة") = MsgBoxResult.Cancel Then Exit Sub Else If MsgBox(" add new image " & Label2.Text & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "ادراج صورة") = MsgBoxResult.Cancel Then Exit Sub End If Application.DoEvents() Dim OFG As New OpenFileDialog OFG.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.GIF)|*.bmp;*.jpg;*.jpeg;*.GIF|" + _ "PNG files (*.png)|*.png|text files (*.text)|*.txt|doc files (*.doc)|*.doc|pdf files (*.pdf)|*.pdf" '"Files(*.jpg)|*.jpg|Files(*.gif)|*.gif|Files(*.bmp)|*.bmp|Files(*.png)|*.png" OFG.Title = "add image" OFG.FileName = "" OFG.FilterIndex = 3 If OFG.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim fs As IO.FileStream = New IO.FileStream(OFG.FileName, IO.FileMode.Open, IO.FileAccess.Read) Dim LoadImage As Image = Image.FromStream(fs) fs.Close() Dim Stream As New IO.MemoryStream() Dim NewBitmap As New Bitmap(LoadImage, 200, 225) NewBitmap.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg) Application.DoEvents() BindingSource1.EndEdit() DataAdapter1.Update(DataSet1.Tables("purch_tb")) DataSet1.Tables("purch_tb").Rows(BindingSource1.Position).Item("pic_prod") = Stream.ToArray Stream.Close() BindingSource1.EndEdit() DataAdapter1.Update(DataSet1.Tables("purch_tb")) Application.DoEvents() MsgBox("image save", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "succ ") End If Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub deletimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deletimage.Click 'delete image Try If PictureBox1.Image Is Nothing Then Beep() : MsgBox("no image found") : Exit Sub If MsgBox(" contenu delete image" & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "delete image") = MsgBoxResult.Cancel Then Exit Sub PictureBox1.Image = Nothing BindingSource1.EndEdit() DataAdapter1.Update(DataSet1.Tables("purch_tb")) MsgBox("image was delete", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "succ ") Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub