Access help: adding/deleting users

bfsog

Well-known member
Joined
Apr 21, 2005
Messages
50
Location
UK
Programming Experience
5-10
Hi. I am very new to db programming using vb.net.

For a project that I am developing, there are upto 25 employees who need to sign in first, only one at a time of course.

I cannot use the dataform wizard as this lets you see the records, I do not need to see them, I just need to log a user in.

Example:

frmSignIn is the startup form. If they supply a correct username/password combo, frmMain is shown, else an error message is displayed.

As I have really no idea about this, I think I am right that I could not use SQL for this such as...

VB.NET:
SELECT * FROM users WHERE Username=txtusername.text AND Password.txtPassword.text ?

So, if you cannot use SQL, what dp I use?

Thanks so much for anyone who helps
 
You can use this code:

VB.NET:
.....Define your  variables con, dst, dta, etc.......

Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click
	Dim clave1 As String = Trim(Me.txtUserName.Text)
	Dim clave2 As String = Trim(Me.txtPassword.Text)
	Me.con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\caritas.mdb"
	dta = New OleDbDataAdapter("Select * from Users where Username = '" & clave1 & "' AND Password = '" & clave2 & "' ", con)
	dst = New DataSet
	dta.Fill(dst, "Users")
	con.Close()
	If Me.dst.Tables("Users").Rows.Count >= 1 Then
	  '.....Access OK......  
	  dim oMainForm as New Main ' Principal Form....
	  oMainForm.ShowDialog()  ' or Show()
	 Else
	  MessageBox.Show("Access Denied")
	 ......Your code.........
	End If
  End Sub

I hope this help you....
 
I forget a little thing: I use the variables CLAVE1 and CLAVE2 (existing in a Module) because I need this values in another part of the application but you can use directly in the SELECT:

......'" & txtUserName.Text & "'....

Regards...
 
Cool. Only one query, you have a comment that reads Define your variables con, dst, dta, etc. I have only used the data form wizard for database connectivity, so will this affect the code you posted?

Btw thanks a lot!
 
I think, yes. Affect!! The wizard create automatically routines, process, functions and Commands (Like Update, Delete,Insert, etc) and you need experience to change them and insert the code I post to you. This is simply my opinion, bfsog. Like a Medicine Doctor, you can find a second opinion :)
 
Jeva39: so if I run the data form wizard, and then create a button/paste in your code, it should work okay?
 
Sorry but is not easy you can add the code in your Data Form Wizard. The management of Datasets, ConnectionStrings, DataAdapters and many other things may cause a conflict with my code and I am 99% sure that don't work. The wizard is very good simply to Navigate across records, create, modify and delete but not for controls process more sofisticated like the access to a system with UserNames and Passwords. Is possible I am wrong because I never use Wizards in VB.NET but also I think my opinion is correct. I hope any person with more experience about this Wizards can help you!!! Write the code have infinites advantages to an application development and, believed me, with VSN is more easy that you can think :)
 
Back
Top