Access 2003
VS 2010 C#
As subject title says I am having a problem with this. It's creating a new field to print date and time when it should be stamping the date and time in the current ID. I have also tried UPDATE command parameter without success.
I have a different method (btnloggedIn) which saves Usernames, Logged In Date and Logged In Time. This works as it should be. I have created another method (btnLoggedOut) which I am having problems with. The purposes is to save Logged Out Date and Logged Out Time when user who logged out, in the came column in Access where Auto ID is created when logged in.
Table Name - LoginTable
>
FieldName Data Type
UserName Text
Password Text
Table name - LoginLogTable
FieldName Data Type
ID AutoNumber
UserName Text
LoggedInDate Date/Time
LoggedInTime Date/Time
LoggedOutDate Date/Time
LoggedOutTime Date/Time
ID is PK. Its one to many relationship. User who logs in can have many details about the date and time details
If anyone can help me here I would be grateful.
private void btnLogOut_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " UPDATE [LoginLogTable] SET [LoggedOutDate] = ?, [LoggedOutTime] = ?
WHERE ID = ?";
cmd.Parameters.AddWithValue("@LoggedOutDate", DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@LoggedOutTime", DateTime.Now.ToString("HH:mm"));
cmd.Connection = myCon;
myCon.Open();
cmd.ExecuteNonQuery();
Close();
}
This the partial code for btnLogin method...
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO LoginLogTable (UserName, LoggedInDate, LoggedInTime) VALUES (@UserName, @LoggedInDate, @LoggedInTime)";
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();