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

Recommended Answers

All 6 Replies

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

I would suggest to uae

textBox7.Text = oreader.GetString(0)

Hope this heslps

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 !!

What problem with the database?

Be a part of the DaniWeb community

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