This is my code so far:
private void loginbtn_Click(object sender, EventArgs e)
{
CRUD.cmd = new NpgsqlCommand("SELECT COUNT(*) FROM users WHERE username = '" + txtuser.Text + "' AND password = '" + txtpass.Text + "'", CRUD.con);
NpgsqlDataAdapter da = new NpgsqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = CRUD.cmd;
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Welcome welcome = new Welcome();
welcome.Show();
this.Hide();
}
else
{
MessageBox.Show("Username or password incorrect, try again.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtpass.Clear();
txtuser.Clear();
txtuser.Focus();
}
if (RememberMe.Checked)
{
Properties.Settings.Default.UserName = txtuser.Text;
Properties.Settings.Default.Password = txtpass.Text;
Properties.Settings.Default.Save();
}
}
I know I should use SQL Parameters, but it's a safe local environment. My question is, how can I retrieve info of which user is currently logged in? I need it so when the user does INSERT method to SQL table, I want to know which user did the entry or which user deleted it. Also to add that users info together with the rest of INSERT method to 2 additional columns (USER ID AND PASS).
Edit:
What I have here is a small windows form application with a datagridview (DGV) and a few text fields to insert values to table with a button, then display that info to DGV, with the ability to delete rows also. I made Form2 so the user has to log in before he gains access to Form1 (DGV Form). All I want to do is to somehow save that users info and whenever he makes a change to DGV, add his credentials to 2 extra columns in the table next to the entry that he has made.