I need help about this, I've been working for this a quiet while...
I want to log-in using one login form for both admin and normal user but after log in, some of its form and/or buttons in the form should not be available for normal users.
here is my code upon login:
Private Sub ok_Click(sender As Object, e As EventArgs) Handles ok.Click
Dim conn As New SqlConnection
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("Please fill in all fields.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
conn.ConnectionString = "Data Source=DOLE-PC\SQLEXPRESS;Initial Catalog=db_dole;Integrated Security=True;"
Try
Dim sql As String = "SELECT UName, Password, Usertype FROM [db_dole].[dbo].[tbl_user] WHERE UName='" & TextBox1.Text & "' AND Password='" & TextBox2.Text & "'"
Dim cmd As New SqlCommand(sql, conn)
cmd.Connection = conn
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
If dr.Read = True Then
If sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Admin'" Then
Me.Hide()
MessageBox.Show(" W E L C O M E !")
mainform.Show()
ElseIf dr.Read = True Then
sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Normal'"
Me.Hide()
MessageBox.Show(" W E L C O M E !")
viewform.Show()
viewform.edit.Visible = False
viewform.Summary.Visible = False
viewform.NewRec.Visible = False
viewform.RFresh.Visible = False
End If
Else
MessageBox.Show("Incorrect Username or Password.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Catch ex As Exception
MessageBox.Show("Failed to connect to databse. System Error:" & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
If conn.State <> ConnectionState.Closed Then
conn.Close()
End If
End If
End Sub