i have two related table name employee and userloginlogs. In my program user must first log username and password located at employee table. If the user already logged in i want to get the employeeID at employee table then save it to userloginlogs table plus the login and logout date of the user.
Take a look at my login button code.
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, ISNULL(password, '') AS password FROM employee WHERE username='" + txtUserName.Text + "' and password='" + txtPassword.Text + "'", Connect);
SqlDataReader dr = cmd.ExecuteReader();
string userText = txtUserName.Text;
string passText = txtPassword.Text;
if (dr.Read())
{
frmMain main = new frmMain();
this.Hide();
main.Show();
}
else
MessageBox.Show("Invalid UserName or Password.");
{
dr.Close();
Connect.Close();
}
}
Can someone help me.
Thanks and regards to daniweb members/user.