I am trying to store the UserID in a global class as the user logs in to their account however i am getting an error.
error: 'Incorrect syntax near 'UserID'. Unclosed quotation mark after the character string '0'.'
Sign in button back-end code:
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM tblUser WHERE Username='" + tb_LoginUsername.Text +
"' AND Password='" + tb_LoginPassword.Text + "'UserID='"+User.UserID , sqlConnection) ;
/* in above line the program is selecting the whole data from table and the matching it with the user name and password provided by user. */
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
User.UserID = int.Parse(dt.Rows[0]["UserID"].ToString());
MainWindow mainWin = new MainWindow();
mainWin.Show();
this.Close();
}
else
{
MessageBox.Show("Login Failed");
}
class:
class User
{
public static int UserID;
}