hi guys i have a big problem how to insert image to database
i had try this out but it returns error(syntex error)

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        OpenFileDialog1.Title = "GET IMAGE"
        OpenFileDialog1.ShowDialog()


    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox1.Text = OpenFileDialog1.FileName

        

    End Sub



    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\database\mpp eelection1.mdb"
        con.Open()
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String

        sql = "SELECT * FROM maklumatpel"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "record")
        con.Close()

        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("record").Rows(0).Item("image") = TextBox1.Text
        da.Update(ds, "record")

        MsgBox("PICTURE UPLOADED")



    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        PictureBox1.Image = Nothing


    End Sub

do anyone can help me
thanks in advance for those helping me
regards -ren-

It is very bad programming to store images in a database. It is much better to instead store the file name and path to point to loading the files.

Images are much larger then text and will quickly accumalate the size of the database. Even if using very small resolution images, everytime you update any field within the same table that whole record is completly recopied (doubling in size) even without updating the actual image. Plus each time your create an index, it duplicates the size of the table. Additionally your using select * to constantly send all this data back and forth between the database and storing in memory.

do any one can help with this problem its really urgent
thanks

'Please try this simple code for inserting a access database record with photo in vb.net

Imports System.IO
Imports System.Data.OleDb

Public Class Form1
    Dim con As New OleDbConnection() 

  Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Dim MemStream As New MemoryStream
        Dim DataPic_Update As Byte()
        Me.PicStudent.Image.Save(MemStream, Imaging.ImageFormat.Png)
        DataPic_Update = MemStream.GetBuffer()
        MemStream.Read(DataPic_Update, 0, MemStream.Length)

        Dim cmd As OleDbCommand = New OleDbCommand("insert into empinfo values('" & txtUserName.Text & "','" & TxtDOB.Text & "','" & txtPOB.Text & "',@EmpPic)", con)

        ' image content
        Dim photo As OleDbParameter = New OleDbParameter("@EmpPic", SqlDbType.Image)
        photo.Value = DataPic_Update
        cmd.Parameters.Add(photo)

        cmd.ExecuteNonQuery()

        MessageBox.Show("Record Is Added")
    End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=C:\Waseem\student.Accdb;"
        con.Open()
        TxtDOB.Text = Today
    End Sub

   Private Sub cmdBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse.Click
        openFileDialog1.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*"
        If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.PicStudent.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName)
        End If
    End Sub
End Class

Thanks.. this solved my problem

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.