怎么根据数据库ID的值来提取那个ID哪一行的数据?

我的是一个登陆页面,用ID的值登陆,然后我用Session把ID存了到另外一个页面想把属于这个ID的用户的信息显示出来,我用的是LABEL..但是我发现我切换了用户的时候,还是显示之前用户的数据,不会自己改变,这是为什么?我贴代码出来..

这是显示用户信息的页面CS
protected void Page_Load(object sender, EventArgs e)
{
time.Text = DateTime.Now.ToString();
employeeID.Text = Session["employeeID"].ToString();

string connString = Convert.ToString(ConfigurationManager.ConnectionStrings["TGKQConnectionString"]);
using (SqlConnection con = new SqlConnection(connString))
{
con.Open();
string strsql = @"select * from tb_user where employeeID=employeeID";
SqlCommand cmd = new SqlCommand(strsql, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
name.Text = dr["name"].ToString();
sex.Text = dr["sex"].ToString();
position.Text = dr["position"].ToString();
power.Text = dr["power"].ToString();
Department.Text = dr["Department"].ToString();
}
}
}

第1个回答  推荐于2018-04-09
employeeID.Text = Session["employeeID"].ToString();
......
string strsql = @"select * from tb_user where employeeID=employeeID";

坦白的说,我没看懂这两行代码。你的SQL不需要拼接出来么?
要是我写的话,可能会是下面这样

exmpoyeeID.Text = Session["employeeID"].ToString();
......
string strsql = @"select * from tb_user where employeeID=" + employeeID.Text;本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网