Hi, I am currently working on a project and I have some questions aswell as some issues that I want to be resolved.
First of all, I am going to give some additional information about my project so that the meaning if it becomes clear.
The project is based on an imaginary enterprise, it delivers computerparts and leases servers. The project is connected to an Access 2007 database. the database has different tables calles users, customers, products and suppliers. each table has records with an id. But for this thread I am going to focus on the users table, this one has the following fields:
- id
- username
- password
- first name
- last name
Now in the project I have set up my connection with the database and I already have made the login form, although that I have 1 small question in it.
here is the code:
Code:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MessageBox.Show("please fill in the required fields.", "Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Dim conn As New System.Data.OleDb.OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Desktop\VBproject\access\GipDB.accdb;Persist Security Info=True;Jet OLEDB:Database Password=********"
Try
Dim sql As String = "SELECT * FROM users WHERE username='" & txtUsername.Text & "' AND password = '" & txtPassword.Text & "'"
Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
sqlCom.Connection = conn
conn.Open()
Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
If sqlRead.Read() Then
'frmMainForm.Show()
MessageBox.Show(GlobalVars.Username & " " & GlobalVars.firstname & " " & GlobalVars.lastname, "info", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Hide()
Else
MessageBox.Show("Username and password do not match.", "Authentication faillure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtPassword.Clear()
txtUsername.Clear()
txtUsername.Focus()
End If
Catch ex As Exception
MessageBox.Show("Failed to connect to Database. System Error Message: " & ex.Message, "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
The question is the following: after the "If sqlRead.Read() Then" I want to insert certain values of the recordset into the following GlobalVars: username, firstname and lastname, all these variables are public declared in a Module. After that, the variables will be shown in the messagebox that follows after it.
the second part of this thread will be focused on the register form, the name explains it already, I want the user to be able to register himself inside the program. the record also has the following fields: id, username, password, firstname, lastname. But I couldn't find anything to my liking on the internet. if you want to help me with this quetion, you may use this to start, you can base your code on my code, mentionned above:
Code:
Private Sub btnSignup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignup.Click
end sub
Thanks in advance
P.S. Sorry for my bad english, as it is not my native language.