Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
Windows Forms
How to create multiple user accounts in database
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Godis, post: 186347, member: 75998"] 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. [CODE=vbnet]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 [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
Windows Forms
How to create multiple user accounts in database
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom