This is the syntax i have written in to compare the text entered in textbox with the database. If existing, the value will be entered in databse, if not, it will give a msgbox displaying to add a new contact.
I am new in The database is Ms Access 2003..

I am getting error on the line : textBox7.Text = oreader["compname"].ToString()

The error says : value of type cannot be converted to type string.

Please help !! Thank you..

Private Sub textBox7_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBox7.Leave

            cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
            cmd = New OleDbCommand("select compname from contactinfo where compname = '" & textBox7.Text & "'", cn)
            Dim oreader = cmd.ExecuteReader()

            If (oreader.HasRows()) Then

                While oreader.Read
                    textBox7.Text = oreader["compname"].ToString()
                End While


                MsgBox("Add New Contact")

            End If

        Catch myException As Exception

            MsgBox("No Record Inserted" + myException.ToString())

            'MsgBox("Closing Connection")

        End Try

    End Sub

check the return type of oreader don't just rely on spoon feeding this problem can be solved easily use google

Thank you so much !!

And yeah, i posted here after searching google only..

Neways, thanx again !! :)

Ruchi224 please mark the thread as solved if its is solved.
It helps the forum to maintain clean.. dont just escape after getting the soluution. Actulally i should post this.. but i saw two of ur post are solved but u forgot to mark as solved.

I did but it showed me the issue of having problem with database. So, i thought will re-try in the evening again !!

Thank you for the reminder, anyways !!

This question has already been answered. Start a new discussion instead.