如何仅检索与在此期间登录的用户相关的数据。

编程入门 行业动态 更新时间:2024-10-25 01:29:55
本文介绍了如何仅检索与在此期间登录的用户相关的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

protected void Page_Load(object sender, EventArgs e) { if (Session.IsNewSession) { Response.Redirect("Login.aspx"); } if (!Page.IsPostBack) { string str = System.Configuration.ConfigurationManager.ConnectionStrings["CensusConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(str); if (con.State == ConnectionState.Closed) { con.Open(); } string @sessionId = System.Web.HttpContext.Current.Session.SessionID; SqlDataAdapter da = new SqlDataAdapter("select * from ureg", con); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { foreach (GridViewRow vrow in GridView1.Rows) { string card = GridView1.DataKeys[vrow.RowIndex].Value.ToString(); string str = System.Configuration.ConfigurationManager.ConnectionStrings["CensusConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(str); if (con.State == ConnectionState.Closed) { con.Open(); } SqlDataAdapter da = new SqlDataAdapter("select * from ureg where card='"+card+"'", con); DataTable dt = new DataTable(); da.Fill(dt); Session["fnm"] = dt.Rows[0]["fname"].ToString(); Session["lnm"] = dt.Rows[0]["lname"].ToString(); Session["gen"] = dt.Rows[0]["gender"].ToString(); Session["cat"] = dt.Rows[0]["catagory"].ToString(); Session["add"] = dt.Rows[0]["adr"].ToString(); Session["dob"] = dt.Rows[0]["dob"].ToString(); Session["ct"] = dt.Rows[0]["city"].ToString(); Session["pin"] = dt.Rows[0]["pin"].ToString(); Session["state"] = dt.Rows[0]["state"].ToString(); Session["mail"] = dt.Rows[0]["mail"].ToString(); Session["ph"] = dt.Rows[0]["phno"].ToString(); Session["card"] = dt.Rows[0]["card"].ToString(); Response.Redirect("update_user.aspx"); } }

I have this code behind file.it is showing all data of the table "ureg" after logged into the page.But i want to retrieve only the data related to the user logged in during that time. please provide me the necessary solution to solve this problem.

推荐答案

您好, 请按照以下步骤 步骤:1 登录登录页面时必须获取用户ID。然后,您可以将用户ID存储在会话对象上。 Hi, Kindly follow the below steps Step: 1 You have to get the user id while logged in login page. then, you can store the user id on session object. session.add("User_Id",txtUserId.Text.ToString().Trim())

步骤:2 登录后成功之后,您可以检查user_id会话对象是否为空状态。然后,您可以请求数据库检索特定用户的数据,如下所示

Step: 2 After you logged in successfully, you can check the user_id session object is null or not condition. then, you can request database to retrieve the data for the particular user as below

if(session["User_Id"]!=null) { string str = System.Configuration.ConfigurationManager.ConnectionStrings["CensusConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(str); if (con.State == ConnectionState.Closed) { con.Open(); } string @sessionId = System.Web.HttpContext.Current.Session.SessionID; SqlCommand cmd=new SqlCommand("Select * from ureg where user_id=@user_id", con); cmd.Parameters.AddWithValue("@user_id",session["User_Id"].ToString().Trim()); SqlDataAdapter da=new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); }

我希望它对你有所帮助

I hope it can be helpful to you

你有SQL显示select * from ureg。只需在其上添加一个where子句,这样你就只能获得所需的行。 You have SQL that shows "select * from ureg". Just add a where clause on to it so you only get back the row you need.

登录时...通过Session获取用户的ID .. 之后 创建一个标签并为其指定会话价值 如果LAble id是lbl_ureg_id则意味着.. lbl_ureg_id.Text = Session [userid]。ToString(); select * from ureg其中uregId ='+ lbl_ureg_id.Text +' During the login... Get The ID of the user by means of Session.. After That Create a label and assign the Session Value on it If LAble id is lbl_ureg_id mean.. lbl_ureg_id.Text=Session["userid"].ToString(); select * from ureg where uregId='"+ lbl_ureg_id.Text +"'

更多推荐

如何仅检索与在此期间登录的用户相关的数据。

本文发布于:2023-10-30 04:02:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在此   数据   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!