|
-
Aug 20th, 2012, 05:24 PM
#1
Thread Starter
New Member
Login Form update query
Hi All,
I am developing a windows form application but am struggling with running an update query when the user logs in,
I basically want the form to validate the user which it does but then i want it to update a field in the users table of an sql database.
The problem is it validates everything ok but it does not run the update query, i check the database table after i run the log in form and it does not update the logged_in field to true, it remains false.
I have
This is the code:highlighted the update query in red.
Code:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim connection As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim adapter As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
connection.ConnectionString = ("Data Source=ALEX-LAPTOP\SQLEXPRESS;Initial Catalog=sldb;Integrated Security=True;Pooling=False")
command.CommandText = "SELECT * FROM [Users] WHERE username='" & txtUsername.Text & "' AND password='" & txtPassword.Text & "';"
connection.Open()
command.Connection = connection
adapter.SelectCommand = command
adapter.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count > 0 Then
command.CommandText = "UPDATE Users SET logged_in=True WHERE username='" & Me.txtUsername.Text & ";"
MsgBox("Login Successful", MsgBoxStyle.Information, "Login Passed")
currentuser = Me.txtUsername.Text
connection.Close()
Me.txtUsername.Clear()
Me.txtPassword.Clear()
Me.Hide()
frmHome.Show()
Else
MsgBox("Invalid Account", MsgBoxStyle.Critical, "Login Failed")
txtUsername.Clear()
txtPassword.Clear()
End If
End Sub
Any help would be greatly appreciated, many thanks in advance!
Last edited by alexcarter404; Aug 20th, 2012 at 05:35 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|