I have given valuable advise from here
But as subject title says I am receiving error in the btnLogin method, related to my previous question but really the same problem, I think? I say this because I was not getting error from my pervious question. Thanks in advance if anyone can help me here.
access 2003 VS 2010 c#
This is my btnLogin method
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO LoginLogTable (UserName, LoggedInDate, LoggedInTime) VALUES (@UserName, @LoggedInDate, @LoggedInTime)";
cmd.CommandText = "SELECT @ID = @@IDENTITY";
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@LoggedInDate", DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@LoggedInTime", DateTime.Now.ToString("HH:mm"));
cmd.Connection = myCon;
myCon.Open();
cmd.ExecuteNonQuery();
myCon.Close();
This is my btnLogOut method.
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " UPDATE [LoginLogTable] SET [LoggedOutDate] = ?, [LoggedOutTime] = ? WHERE ID = @ID";
cmd.Parameters.AddWithValue("@LoggedOutDate", DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@LoggedOutTime", DateTime.Now.ToString("HH:mm"));
cmd.Connection = myCon;
myCon.Open();
cmd.ExecuteNonQuery();
The purpose of the code the code is record the date and time when user logs in and the date and time when the user logs out.
Update 2 I have tried this as well...
cmd.CommandText = "INSERT INTO LoginLogTable (UserName, LoggedInDate, LoggedInTime) VALUES (@UserName, @LoggedInDate, @LoggedInTime)" + "SELECT @ID = @@IDENTITY";
Then I am receiving error of...
Missing semicolon (;) at end of SQL statement.
Update 3
cmd.CommandText = "INSERT INTO LoginLogTable (UserName, LoggedInDate, LoggedInTime) VALUES
(@UserName, @LoggedInDate, @LoggedInTime)"; "SELECT @ID = @@IDENTITY";
I have placed a ; and I am getting error of...
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Looking at other solutions provided my other members
Update 4
I think some of the advise here may only work for SQL Server. I am using MS Access 2003.
Update 5
cmd.CommandText = "INSERT INTO LoginLogTable (UserName, LoggedInDate, LoggedInTime) VALUES
(@UserName, @LoggedInDate, @LoggedInTime); SELECT @ID = @@IDENTITY";
receiving error...
Characters found after end of SQL statement.