OK I have an assignment on my Access course, I find this site really good and require some help if possible.
Basically I have a login screen which checks the Access Database I am using the code I have is this:
Username = txtUsername.Text Password = txtPassword.Text 'Following code connects the program to the access database. connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\Users\BlackVIPER09\Documents\Visual Studio 2008\Projects\Primary School Maths Test\PrimaryMaths.mdb" 'This is the program opening the database, checking the users login and then closes the database. connection.Open() sql = "SELECT * FROM MathsTest WHERE LoginName = '" & Username & "' AND Password= '" & Password & "'" adaptor = New OleDb.OleDbDataAdapter(sql, connection) adaptor.Fill(ds, "TestInfo") connection.Close()
OK next is the problem I am having, the above code is working fine. BUT when the user has completed a test and I want to apply data into the database under the person that has logged in how do I do this? As I understand I need to use UPDATE so have written the following code in the place I need to add the persons test results:
'Connection to the Database connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\Users\BlackVIPER09\Documents\Visual Studio 2008\Projects\Primary School Maths Test\PrimaryMaths.mdb" 'This is to insert a new user and password into the database command.Connection = connection command.CommandText = "UPDATE MathsTest" & "(Easy_Time, Easy_Date)" & "VALUES(@EasyTime, @EasyDate)" command.Parameters.AddWithValue("@EasyTime", lblDate.Text) command.Parameters.AddWithValue("@Password", lblTimer.Text) connection.Open() command.ExecuteNonQuery() connection.Close()
I think the code is right but, tell me if I am wrong I am ment to set a position for the user when they login?? Please help I have tried to research this and not finding a thing.
Any code would be appreciated!!