[英]How to store UserID in a class when they sing in?
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.当用户登录到他们的帐户时,我试图将 UserID 存储在一个全局类中,但是我收到一个错误。
error: 'Incorrect syntax near 'UserID'.错误:''UserID' 附近的语法不正确。 Unclosed quotation mark after the character string '0'.'
字符串'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;
}
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM tblUser WHERE Username='" + tb_LoginUsername.Text +
"' AND Password='" + tb_LoginPassword.Text + "'", 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");
}
removed :删除:
"'UserID='"+User.UserID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.