hi ....

im tring to insert a picture with some information to the database
when i run the progaram it will display the bellow message

NullRefaranceExprasion was Unhandle
Object reference not set to an instance of an object.

this is my full code
is there is any mistake?

Imports System.IO
Imports System.Configuration
Public Class Form8
    Dim A As String = ConfigurationSettings.AppSettings("Datapath")
    Dim con1 As New OleDb.OleDbConnection(A)
    Dim com111 As OleDb.OleDbCommand
    Dim dar As OleDb.OleDbDataReader
    Dim sqlrt As String




    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TabControl1.SelectTab(TabPage1)
        Me.Hide()
        Form3.Show()

    End Sub

    Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Module1.connrtol()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
        Dim breader As New BinaryReader(fsreader)

        Dim imgbuffer(fsreader.Length) As Byte
        breader.Read(imgbuffer, 0, fsreader.Length)
        fsreader.Close()


        sqlrt = "INSERT INTO Employee(EId,DNo,FName,MName,LName,Address_Line1,Address_Line2,Address_Line3,NIC,DOB,Gender,Telephone,E_mail,Emp_Photo)VALUES(@dtaEId,@dtaDNo,@dtaFname,@dtaMName,@dtaLName,@dtaAddress1,@dtaAddress2,@dtaAddress3,@dtaNIC,@dataDOB,@dtaGender,@datTele,@dtaEmail,@dtaPhoto) "
        com1.CommandText = sqlrt
        com1.Connection = con1
        com1.Parameters.AddWithValue("@dtaEId", ECODEMasked1.Text)
        com1.Parameters.AddWithValue("@dtaDNo", DEPcodeMasked.Text)
        com1.Parameters.AddWithValue("@dtaFname", TextBox3.Text)
        com1.Parameters.AddWithValue("@dtaMName", TextBox4.Text)
        com1.Parameters.AddWithValue("@dtaLName", TextBox5.Text)
        com1.Parameters.AddWithValue("@dtaAddress1", TextBox6.Text)
        com1.Parameters.AddWithValue("@dtaAddress2", TextBox7.Text)
        com1.Parameters.AddWithValue("@dtaAddress3", TextBox8.Text)
        com1.Parameters.AddWithValue("@dtaNIC", EMasked2.Text)
        com1.Parameters.AddWithValue("@dataDOB", EDOBPicker1.Value.Date)
        com1.Parameters.AddWithValue("@dtaGender", ComboBox3.SelectedItem)
        com1.Parameters.AddWithValue("@datTele", ETELEMasked3.Text)
        com1.Parameters.AddWithValue("@dtaEmail", TextBox10.Text)
        com1.Parameters.AddWithValue("@dtaPhoto", imgbuffer)
        com1.ExecuteNonQuery()
        MsgBox("Successsfuly Inserted", MsgBoxStyle.Information)
        con.Close()


        'com1 = New OleDb.OleDbCommand("INSERT INTO Employee(EId,DNo,FName,MName,LName,Address_Line1,Address_Line2,Address_Line3,NIC,DOB,Gender,Telephone,E_mail,Emp_Photo)VALUES('" + ECODEMasked1.Text + "','" + DEPcodeMasked.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + EMasked2.Text + "' ,'" + EDOBPicker1.Value.Date + "','" + ComboBox3.SelectedItem + "','" + ETELEMasked3.Text + "','" + TextBox10.Text + "'," + imgbuffer. + ")", con1)

        ''Dim com4 As New OleDb.OleDbCommand("INSERT INTO Employee(E-mail)VALUES('" + TextBox9.Text + "')", con1)
        'Debug.WriteLine(com1)
        'com1.ExecuteNonQuery()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Filter = "Image File (* .jpg, *.bmp, *.png) | *.jpg; *.bmp; *.png| all files (*.*) | *.* "
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
        End If
    End Sub

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

    End Sub
End Class

Line 34 and beyond uses com1 which is undefined. What's on line 55 should be before 34 I think.

how do i correct that ?

Use a text editor?

i used new keyword .now is ok
but is it will display a anothe error

Data type mismatch in criteria expression.

thanx my friends ...

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.