I'm using the following codes to see if the Name of the User that will be enter in a TextBox is a Valid Name in my Database Table.So far this codes are not working for me at the same time I'm not getting any errors but when I click the command button to return my Result I get the Error Message. Which mean no data was return or Found.
If strResult = "" Then ' it didnt return any rows
MsgBox("Error message!!")
Else
' it returned something
End If
This are the codes I'm using
Dim Result as String
If txtUser.Text = "" Then
MyDataAdapter.SelectCommand = New OLEDBConnection ()
MyDataAdapter.SelectCommand.Connection = MyConnection ()
MyDataAdapter.SelectCommand.CommandText = "Select UserID From UserTable WHERE UserID= '" & txtUser.Text & "'"
MyConnection.Open ()
Result = MyDataAdapter.SelectCommand.ExecuteScalar ()
Catch ex as Exception
Result = ""
MyConnection.Close
If Result = "" Then
MsgBox ("Error Message!!")
Else
MessageBox.Show (" User is Valid")
End If
What could be wrong with this codes. All I'm trying to do is make it work like a Log on. When any user uses a LogOn screen he first Enter his Name and then his Password once he clicks on the command button then it check if the User exists in the Database and then it check for the Password. I would like to check if the user Exists in the Database table.My Datatype for the Coulmn is Text. The Column the Name will be on is called UserID the table is called NewUser. The TextBox the Name is going to be enter is called txtUserID.





