Could someone please look over this code and see what I am doing wrong? I can successfully connect to the database however if I true to Select the record that matches the Surname a user enters from the database it returns an error:
----------------------------
"An unhandled exception of type 'System.InvalidOperationException' occurred in microsoft.data.odbc.dll
Additional information: No data exists for the row/column.
-----------------------------
Here is my code:
----------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As OdbcConnection
cn = New OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=c:\Mouse Tails\Database\prototype1.mdb;UID=;PWD="
cn.Open()
Dim mystring As String = "Select * from Owner where OwnerSname Like 'UserName.Text'"
Dim cmd As OdbcCommand = New OdbcCommand(mystring, cn)
Dim myReader As OdbcDataReader
Dim Fname As Object
myReader = cmd.ExecuteReader()
If myReader("OwnerFname" <> 0 Then
Password.Text = myReader("OwnerFname"
End If
cn.Close()
End Sub
-----------------------------------------------------
----------------------------
"An unhandled exception of type 'System.InvalidOperationException' occurred in microsoft.data.odbc.dll
Additional information: No data exists for the row/column.
-----------------------------
Here is my code:
----------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As OdbcConnection
cn = New OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=c:\Mouse Tails\Database\prototype1.mdb;UID=;PWD="
cn.Open()
Dim mystring As String = "Select * from Owner where OwnerSname Like 'UserName.Text'"
Dim cmd As OdbcCommand = New OdbcCommand(mystring, cn)
Dim myReader As OdbcDataReader
Dim Fname As Object
myReader = cmd.ExecuteReader()
If myReader("OwnerFname" <> 0 Then
Password.Text = myReader("OwnerFname"
End If
cn.Close()
End Sub
-----------------------------------------------------