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





myCommand.Parameters.Add(uName)
myCommand.Parameters.Add(uPassword)
myCommand.Parameters.Add(uType)

myCommand.Connection.Open()



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

Dim Login As Object = 0

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

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


' Administrator Roles : 

If uType.Value = "admin" Then

myCommand.Parameters.Add(uType)
MessageBox.Show("User identified as Admin, logging in")

Form1.Show()
Form1.SystemToolStripMenuItem.Enabled = True
Form1.ReportToolStripMenuItem.Enabled = True
Else

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

End If




End If

'............


Me.Hide()


End If

End Sub

...

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

Could you help me , please ?

Recommended Answers

All 2 Replies

"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 ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.