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