I have Database name LoginUser with corresponding fields name such as User, Login and Logout. Im done in inserting data once the user Log to the system. Heres the sample layout once the user tried to log.
User................Login............................Logout
Abigail.........12/29/2010 3:08:42 PM
James..........12/29/2010 3:09:45 PM
Abigail.........12/29/2010 3:30:45 PM
PROBLEM:
1) I want to update the user with the same username BUT HOW?
2) Plus how to update the logout field when the user try to exit the program?
Heres my code for now:
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection Connect = new SqlConnection();
Connect.ConnectionString = @"Data Source=BURBANK\SQLEXPRESS;" + "Initial Catalog= ERPdb;" + "Persist Security Info=True;" + "User ID=antonette;" + "Password=ilovemis";
Connect.Open();
SqlCommand cmd = new SqlCommand("SELECT ISNULL(username, '') AS username, employeeID, ISNULL(password, '') AS password FROM employee WHERE username='" + txtUserName.Text + "' and password='" + txtPassword.Text + "'", Connect);
string userText = txtUserName.Text;
string passText = txtPassword.Text;
string fisrt = txtempID.Text;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
frmMain main = new frmMain();
txtempID.Text = Convert.ToString(dr[1]);
main.Show();
dr.Close();
SqlCommand cmdLogin = new SqlCommand("INSERT INTO UserLoginLogs(EmployeeID,LoginDate)VALUES ('" + txtempID.Text + "',getDate())", Connect);
SqlDataReader dr1 = cmdLogin.ExecuteReader();
}
else
MessageBox.Show("Invalid UserName or Password.");
{
dr.Close();
}
try
{
}
catch (SqlException ex)
{
MessageBox.Show("There is an Error" + ex);
}
finally
{
Connect.Close();
}
}
Hope someone can help me with this. Thanks in advance.