Thanks for the advice everyone and sorry for being lazy! i have had a look through some of the code banks and edited my code.
I have updated the login process to not use a dataset which works fine but i am having trouble running the update query still! I will implement the hash algorithm at a later date as i have not made a registration form to hash inputted data yet which means i cannot yet compare to a hash value.
The problem i am having is that i get an error of sqlexception was unhandled - invalid column name true. This is when running the update query section of the code
Code:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'create connection string and connect to db
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = ("Data Source=ALEX-LAPTOP\SQLEXPRESS;Initial Catalog=sldb;Integrated Security=True;Pooling=False")
Try
conn.Open()
Catch myerror As Exception
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
End Try
'create query, execute and put into reader
Dim myAdapter As New SqlClient.SqlDataAdapter
Dim sqlquery = "SELECT username, password FROM Users Where username='" & txtUsername.Text & "' and password='" & txtPassword.Text & "'"
Dim myCommand As New SqlClient.SqlCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdapter.SelectCommand = myCommand
Dim myData As SqlClient.SqlDataReader
myData = myCommand.ExecuteReader()
'check for correct credentials
If myData.HasRows = 0 Then
MessageBox.Show("Invalid Login Details", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
currentuser = Me.txtUsername.Text
'run update query to update logged_in field to true
conn = New SqlClient.SqlConnection
conn.ConnectionString = ("Data Source=ALEX-LAPTOP\SQLEXPRESS;Initial Catalog=sldb;Integrated Security=True;Pooling=False")
conn.Open()
Dim sqlquery2 = "UPDATE Users SET logged_in=True WHERE username='" & txtUsername.Text & "' and password='" & txtPassword.Text & "'"
Dim mycommand2 As New SqlClient.SqlCommand(sqlquery2, conn)
mycommand2.ExecuteNonQuery()
Dim homeform = New frmHome
homeform.Show()
Me.Visible = False
End If
End Sub
Am i running the update query correctly? I know i need to run it as an executenoquery but for some reason it doesn't like the update query. Any Suggestions?