0

This is the syntax i have written in vb.net 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 vb.net. The database is Ms Access 2003..

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

The error says : value of type system.data.oledb.oledbdatareador 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

        Try
            'MsgBox("Open")
            cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
            cn.Open()
            'Ole()
            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

            Else

                MsgBox("Add New Contact")

            End If

        Catch myException As Exception

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

        Finally
            'MsgBox("Closing Connection")

            cn.Close()
        End Try


    End Sub
5
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by Netcode
0

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

0

Thank you so much !!

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

Neways, thanx again !! :)

0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.