I am developing a windows form application project and want to create separate accounts for the Admin, Accountant, Manager and Guest. Inside the project are login dashboards for these users.
The user access control table is created in the sql server 2016 and connected successfully to the project. Login form with the various access has also been successfully created. When each user logs in I want his respective dashboard to show.
When I run the project, an error message shows up. Please I will appreciate if someone can help me fix the problem.
I attach the code and the error message for correction.
The user access control table is created in the sql server 2016 and connected successfully to the project. Login form with the various access has also been successfully created. When each user logs in I want his respective dashboard to show.
When I run the project, an error message shows up. Please I will appreciate if someone can help me fix the problem.
I attach the code and the error message for correction.
VB.NET:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class frmUserControl
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Private Sub frmUserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Dim con As SqlConnection = New SqlConnection("Data Source=DAVID;Initial Catalog=Projects;Integrated Security=True")
con.Open()
Dim cmd As SqlCommand = New SqlCommand("select * from UsersAccess where username = '" & txtUsername.Text & "' and password = '" & txtPassword.Text & "'", con)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
Dim username = txtUsername
Dim password = txtPassword
da.Fill(dt)
If (dt.Rows.Count > 0) Then
MessageBox.Show("You Are Successfully Logged In!")
End If
txtUsername.Clear()
txtPassword.Clear()
Me.Hide()
cmd = New SqlCommand("select Role from UsersAccess where username = @username", con)
cmd.Parameters.AddWithValue("@username", username)
Dim role As String = cmd.ExecuteScalar()
MsgBox("You Are Welcomed Back" + role)
con.Close()
Dim admin As New Admin
Dim acc As New Accountant
Dim mg As New Manager
Dim gt As New Guest
If role = "Admin" Then
admin.Show()
ElseIf role = "Accountant" Then
acc.Show()
ElseIf role = "Manager" Then
mg.Show()
ElseIf role = "Guest" Then
gt.Show()
Else
MessageBox.Show("Invalid Username or Password; Please Verify!")
End
con.Close()
End If
End Sub
End Class
Attachments
Last edited: