如何进一步使用数据库中的retrive值 [英] how to further use retrive values from database
本文介绍了如何进一步使用数据库中的retrive值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题可能很简单,但我无法解决这个问题,假设我在查询中检索用户详细信息,即
My Question may be very simple but i am not able to solve this problem lets say i am retrieving user details in a query i.e
SqlCommand comand = new SqlCommand("Select Userid,UserName,Password FROM Users WHERE UserName=@Uname and Password = @Pass", con);
comand.Parameters.AddWithValue("@Uname", this.txtUsername.Text);
comand.Parameters.AddWithValue("@pass", this.txtPassword.Text);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(comand);
DataTable t = new DataTable();
adp.Fill(t);
我想单独使用Userid进一步在查询中使用,或者我可以存储已经进入的用户的USerid进入Session如何做到这一点??
I want to get Userid separately to further use in a Query or i may store USerid of the user who has loged in into Session How i can do this??
推荐答案
将它存储在会话中,非常简单:
Store it in the session, it's pretty simple:
Session["UserId"] = myUserId;
然后
And then
if (Session["UserId"] == null)
{
... redirect to login page
}
else
{
string userId = (string) Session["UserId"];
...
}
但请不要这样做!切勿以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]
SqlCommand comand = new SqlCommand("Select Userid,UserName,Password FROM Users WHERE UserName=@Uname and Password = @Pass", con);
comand.Parameters.AddWithValue("@Uname", this.txtUsername.Text);
comand.Parameters.AddWithValue("@pass", this.txtPassword.Text);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(comand);
DataTable t = new DataTable();
adp.Fill(t);
string userId;
foreach(DataRow dr in t.Rows)
{
userId = dr["Userid"].ToString();
}
然后将其存储在会话中,即
and then store it in the session, i.e
Session["userId"] = userId;
希望这是很清楚:)
-KR
Hope this is pretty clear to you :)
-KR
这篇关于如何进一步使用数据库中的retrive值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文