hi ,

I'm using VB.net :
I want to create login and check if the user is admin or not from the table in the database .

in my database i have table(Log_in) contains : user name , Password , User Type .

I create Login Form :

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

Dim vCon As New SqlConnection
vCon.ConnectionString = "..... "
Dim vSelectCommand As New SqlCommand

Dim myCommand As SqlCommand
myCommand = New SqlCommand("SELECT [User_Name],[Password],[User_Type] FROM Log_in WHERE [User_Name] = @UserName AND [Password] = @UserPassword AND [User_Type] = @UserType", vCon)

Dim uName As New SqlParameter("@UserName", SqlDbType.NVarChar)
Dim uPassword As New SqlParameter("@UserPassword", SqlDbType.NVarChar)
Dim uType As New SqlParameter("@UserType", SqlDbType.NVarChar)

uName.Value = UsernameTextBox.Text
uPassword.Value = PasswordTextBox.Text

"uType.Value = "admin



Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

Dim Login As Object = 0

If myReader.HasRows Then
Login = myReader(Login)
End If

If Login = Nothing Then
MessageBox.Show("sorry ....")

' Administrator Roles : 

If uType.Value = "admin" Then

MessageBox.Show("User identified as Admin, logging in")

Form1.SystemToolStripMenuItem.Enabled = True
Form1.ReportToolStripMenuItem.Enabled = True

If uType.Value = "user" Then
MessageBox.Show("Login successful")
Form1.SystemToolStripMenuItem.Enabled = False
Form1.ReportToolStripMenuItem.Enabled = False

End If

End If



End If

End Sub


The Problem is the user Type its only work correctly with admin ,

Could you help me , please ?

"SELECT [User_Name],[Password],[User_Type] FROM Log_in WHERE [User_Name] = @UserName AND [Password] = @UserPassword " and then check which User_Type this user has. I won't correct the rest of your code, you can surely do it yourself.

acually I don't know how to complete the code , where should I declare the user type ?!

could you write the code , please ?

This article has been dead for over six months. Start a new discussion instead.