Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click

        'to check if the records already exists...
        Dim sqlQRY As String = "SELECT COUNT(namee) AS namecount from staff WHERE namee='" & TextBox7.Text & "'"
        Dim queryResult As Integer

        Dim com As New OleDbCommand(sqlQRY, conn)
        queryResult = com.ExecuteScalar()

        If queryResult > 0 Then
            MessageBox.Show("Data Already Exists!", "REMINDER ", MessageBoxButtons.OK, MessageBoxIcon.Information)

            'if above if.. statement is false then else part is executed

            Dim arrImage() As Byte
            Dim strImage As String
            Dim myMs As New IO.MemoryStream
            If Not IsNothing(Me.PictureBox1.Image) Then
                Me.PictureBox1.Image.Save(myMs, Me.PictureBox1.Image.RawFormat)
                arrImage = myMs.GetBuffer
                strImage = "?"
                arrImage = Nothing
                strImage = "NULL"
            End If

            Dim myCmd As New OleDb.OleDbCommand
            myCmd.Connection = conn

            myCmd.CommandText = "INSERT INTO staff(namee,address,contact,position,dob,entry_date,salary,picture) VALUES('" & Me.TextBox7.Text & "','" & Me.TextBox8.Text & "','" & Me.TextBox9.Text & "','" & Me.ComboBox5.Text & "','" & Me.DateTimePicker4.Text & "','" & Me.DateTimePicker3.Text & "','" & Me.TextBox10.Text & "'," & strImage & ")"
            If strImage = "?" Then
                myCmd.Parameters.Add(strImage, OleDb.OleDbType.Binary).Value = arrImage
            End If
            MessageBox.Show("Data sucessfully saved..", "Sucess!!!", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

hi sir.. i couldnt figure out the problem heres my code for inserting images to access database. it always throws error oledbexception was unhandeled in insert into query.. whats the actual problem.. plz help me...

3 Years
Discussion Span
Last Post by tareywolf
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.