I have a registration page wich is working fine, so I can add user. The problem is the login page, it alwais says that the login is invalid and I cant figure out what is wrong. I am using mysql.

Here is the login code:

Imports:
VB Code:
  1. Imports System.Web.Security
  2. Imports System.Configuration
  3. Imports MySql.Data.MySqlClient
  4. Imports MySql.Data
  5.  
  6. Imports System.Data.OleDb

Function:
VB Code:
  1. Partial Class login2
  2.     Inherits System.Web.UI.Page
  3.     Public storecons As String
  4.     Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
  5.         storecons = _
  6.         "SELECT COUNT(*) AS Num_of_User " & _
  7.         "FROM tblUser " & _
  8.         "WHERE U_Name = @UserName AND U_Password = @Password "
  9.  
  10.         Dim MyConn As MySqlConnection = New MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
  11.         Dim MyCmd As New MySqlCommand(storecons, MyConn)
  12.         MyCmd.CommandType = Data.CommandType.Text
  13.         Dim objParam1, objParam2 As MySqlParameter
  14.  
  15.         objParam1 = MyCmd.Parameters.Add("@UserName", MySqlDbType.VarChar)
  16.         objParam2 = MyCmd.Parameters.Add("@Password", MySqlDbType.VarChar)
  17.  
  18.         objParam1.Direction = Data.ParameterDirection.Input
  19.         objParam2.Direction = Data.ParameterDirection.Input
  20.  
  21.         objParam1.Value = txtUserName.Text
  22.         objParam2.Value = txtPassword.Text
  23.  
  24.         Dim objReader As OleDbDataReader
  25.  
  26.         '   |||||   Try, catch block!
  27.         Try
  28.             '   |||||   Check if Connection to DB is already open, if not, then open a connection
  29.             If MyConn.State = Data.ConnectionState.Closed Then
  30.                 '   |||||   DB not already Open...so open it
  31.                 MyConn.Open()
  32.             End If
  33.  
  34.             '   |||||   Create OleDb Data Reader
  35.  
  36.             objReader = MyCmd.ExecuteScalar(Data.CommandBehavior.CloseConnection)
  37.             '   |||||   Close the Reader and the Connection Closes with it
  38.  
  39.             While objReader.Read()
  40.                 If CStr(objReader.GetValue(0)) <> "1" Then
  41.                     lblMessage.Text = "Invalid Login!"
  42.                 Else
  43.                     objReader.Close()   '   |||||   Close the Connections & Reader
  44.                     Return True
  45.                 End If
  46.             End While
  47.         Catch ex As Exception
  48.             lblMessage.Text = "Error Connecting to Database!"
  49.         End Try
  50.     End Function

Login button:
VB Code:
  1. Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
  2.         If Page.IsValid Then    '   ||||| Meaning the Control Validation was successful!
  3.             '   |||||   Connect to Database for User Validation |||||
  4.             If DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then
  5.                 FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)  '   |||||   default.aspx Page!
  6.                 Session("User") = txtUserName.Text
  7.             Else
  8.                 '   |||||   Credentials are Invalid
  9.                 lblMessage.Text = "Invalid Login!"
  10.             End If
  11.         End If
  12.     End Sub

I hope someone can help me!

Thanks!