Private Sub LOGIN_BUTTON_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles LOGIN_BUTTON.Click
Try
con = New
SqlConnection(Module1.mod1)
con.Open()
sql = "select
* from M_LOGIN WHERE LOGIN_ID = '" & Me.UsernameTextBox.Text
& "' and pass1 = '" & Me.PasswordTextBox.Text & "' and pass2 = '" & Me.PasswordTextBox.Text
& "'"
cmd = New
SqlCommand(sql, con)
dr = cmd.ExecuteReader
If
dr.Read() Then
Form1.Show()
Me.Hide()
Else
: MsgBox("Invalid UserName or Password",
16, "LOGIN ERROR")
End
If
Catch
es As Exception
MsgBox(es.Message)
End Try
con.Close()
Me.UsernameTextBox.Clear()
Me.PasswordTextBox.Clear()
Me.UsernameTextBox.Select()
End Sub
USING WHILE LOOP / IF
ELSE
Imports
System.Data.OleDb
Imports
System.Data
Public Class login
Dim con As OleDbConnection, cmd As
OleDbCommand
Dim str1 As String
Dim str2 As String
Private Sub Login_Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
con = New
OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data
Source=" & Application.StartupPath & "\database1.mdb;Persist security Info=False")
str1 = "select
[StudentNumber],[StudentPassword] from [Members] WHERE [StudentNumber] like
'" & Trim(TextBox1.Text) & "'
and [StudentPassword] like '" & Trim(TextBox2.Text) & "';"
str2 = "select
[AUserName],[APassword] from [Members2] WHERE [AUserName] like '"
& Trim(TextBox1.Text) & "' and
[APassword] like '" & Trim(TextBox2.Text) & "';"
cmd = New
OleDbCommand(str1, con)
cmd2 = New
OleDbCommand(str2, con)
Dim dr As OleDbDataReader
Dim dr2
As OleDbDataReader
dr = cmd.ExecuteReader
dr2 = cmd2.ExecuteReader
If
dr.HasRows = False Then
If
dr2.HasRows = False Then
MsgBox("Please
enter a correct username or password")
End
If
Else
While
(dr.Read())
If
(TextBox1.Text = dr(0).ToString()) And
(TextBox2.Text = dr(1).ToString()) Then
student_form.Show()
Me.Hide()
TextBox1.Text = ""
TextBox2.Text = ""
End
If
End
While
dr.Close()
End If
While
(dr2.Read())
If
(TextBox1.Text = dr2(0).ToString()) And
(TextBox2.Text = dr2(1).ToString()) Then
admin_form.Show()
Me.Hide()
TextBox1.Text = ""
TextBox2.Text = ""
End
If
End While
dr.Close()
cmd = Nothing
cmd2 = Nothing
con.Close()
End Sub
Private Sub Cancel_Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
Me.Dispose()
End Sub
End Class
No comments:
Post a Comment