Tinkerbell
Member
- Joined
- Sep 9, 2009
- Messages
- 14
- Programming Experience
- 1-3
How to check if string entered in a text box matches a field in a data table
Hello
I have a form with two text boxes for users to enter their Username and Password. When they enter their details and click the 'Login' button I want their details to be
checked against data in a data table to see if they match or not. I am using an 'if...else' statement but can't work out the syntax to use. My code is as follows:
[
Imports System.Data.OleDb
Imports System
Public Class frmLogin
Dim OleDBConn As New OleDbConnection() 'The OleDB Connection
'Connstring = Server Name, Database Name, Windows Authentication
'Declare inside of class >
Dim SQLStr As String
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'check Username & Password against records in tblLogin
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\K0201227Project.accdb;Persist Security Info=False;"
'Connection String
OleDBConn.ConnectionString = ConnString 'Set the Connection String
'SQL string
SQLStr = "SELECT * FROM tblLogin"
'New datatable
Dim ds As New DataTable
'New table adapter, passing the sql string and connection
Dim da As New OleDbDataAdapter(SQLStr, OleDBConn)
'fill the table ds with data selected from the sql string
da.Fill(ds)
''''this is the part i'm stuck on''''
If txtUsername.Text = ds????Username Then AND txtPassword.Text = ???Password Then
MessageBox.Show("Successfully logged in")
Else
MessageBox.Show("The Username or Password you entered is incorrect")
End If
End Sub
End Class
]
The fields I want to match the textbox strings against in my database table are called 'Username' and 'Password'.
Appreciate any help! Let me know if you need more info.
Thanks
Amy
Hello
I have a form with two text boxes for users to enter their Username and Password. When they enter their details and click the 'Login' button I want their details to be
checked against data in a data table to see if they match or not. I am using an 'if...else' statement but can't work out the syntax to use. My code is as follows:
[
Imports System.Data.OleDb
Imports System
Public Class frmLogin
Dim OleDBConn As New OleDbConnection() 'The OleDB Connection
'Connstring = Server Name, Database Name, Windows Authentication
'Declare inside of class >
Dim SQLStr As String
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'check Username & Password against records in tblLogin
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\K0201227Project.accdb;Persist Security Info=False;"
'Connection String
OleDBConn.ConnectionString = ConnString 'Set the Connection String
'SQL string
SQLStr = "SELECT * FROM tblLogin"
'New datatable
Dim ds As New DataTable
'New table adapter, passing the sql string and connection
Dim da As New OleDbDataAdapter(SQLStr, OleDBConn)
'fill the table ds with data selected from the sql string
da.Fill(ds)
''''this is the part i'm stuck on''''
If txtUsername.Text = ds????Username Then AND txtPassword.Text = ???Password Then
MessageBox.Show("Successfully logged in")
Else
MessageBox.Show("The Username or Password you entered is incorrect")
End If
End Sub
End Class
]
The fields I want to match the textbox strings against in my database table are called 'Username' and 'Password'.
Appreciate any help! Let me know if you need more info.
Thanks
Amy