How to Save and retrieve picture in access data base with vb.net 2008

Check out this thread.

Also take a look here:
http://www.vbdotnetheaven.com/UploadFile/aghiondea2/StoringImagesInVB11122005034248AM/StoringImagesInVB.aspx

And here is a code snippet

File name is Image.vb
Imports System
Imports System.IO
Imports System.Data
Public Class SaveImage
Shared Sub main()
Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String
Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine
If Dir(gifFile) = "" Then
   Console.Write("Invalid File Path")
   Exit Sub
End If
o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)
Try
Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data 
Source=Test.mdb")
Dim Sql As String = "INSERT INTO Images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
End Class

*borrowed from here

Check out this thread.

Also take a look here:
http://www.vbdotnetheaven.com/UploadFile/aghiondea2/StoringImagesInVB11122005034248AM/StoringImagesInVB.aspx

And here is a code snippet

File name is Image.vb
Imports System
Imports System.IO
Imports System.Data
Public Class SaveImage
Shared Sub main()
Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String
Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine
If Dir(gifFile) = "" Then
   Console.Write("Invalid File Path")
   Exit Sub
End If
o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)
Try
Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data 
Source=Test.mdb")
Dim Sql As String = "INSERT INTO Images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
End Class

*borrowed from here

Its not working dear the other link u gave id for sql i need code for visual basic 2008 i tried this one but it save picture just in run time not saving in access data base file

Public Class Form1
    Private path As Bitmap
    Private Sub PicBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.PicBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PictureDataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'PictureDataSet.pic' table. You can move, or remove it, as needed.
        Me.PicTableAdapter.Fill(Me.PictureDataSet.pic)
        'TODO: This line of code loads data into the 'PictureDataSet.pic' table. You can move, or remove it, as needed.
        Me.PicTableAdapter.Fill(Me.PictureDataSet.pic)
        'TODO: This line of code loads data into the 'PictureDataSet.pic' table. You can move, or remove it, as needed.
        Me.PicTableAdapter.Fill(Me.PictureDataSet.pic)

    End Sub

    Private Sub PicBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.PicBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PictureDataSet)

    End Sub

    Private Sub IDTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PICLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub IDLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PICPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        path = New Bitmap(OpenFileDialog1.FileName)
        PICPictureBox.Image = path
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub PicBindingNavigatorSaveItem_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PicBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PicBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PictureDataSet)

    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click

    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.