---
title: "How to get logged user id c#"  
description: "How to get logged user id c#"  
author: "Anonymous User"  
published: 2013-12-17  
updated: 2013-12-17  
canonical: https://www.mindstick.com/forum/1782/how-to-get-logged-user-id-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get logged user id c#

I have created a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [login](https://www.mindstick.com/articles/12852/styles-login-form-in-android) [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) but I got [problem with getting](https://www.mindstick.com/forum/142/problem-with-getting-id-of-control-where-item-is-dropped) logged in [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) ID

```
public partial class LoginwithEncryption : System.Web.UI.Page{    protected void btnSubmit_Click(object sender, EventArgs e)    {        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);        con.Open();        SqlCommand cmd = new SqlCommand(            "select * from dbo.UserInfo where Login =@Login and Password=@Password", con);        cmd.Parameters.AddWithValue("@Login", txtUserName.Text);        cmd.Parameters.AddWithValue("@Password", txtPWD.Text);        SqlDataAdapter da = new SqlDataAdapter(cmd);        DataTable dt = new DataTable();        da.Fill(dt);        if (dt.Rows.Count > 0)        {            Response.Redirect("StartPage.aspx");        }        else        {            ClientScript.RegisterStartupScript(Page.GetType(), "validation",                "<script language='javascript'>alert('Invalid UserName and Password')</script>");        }    }}
```

How can I get ID of user after login (I'm able to login) ? I tried few [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) but it won't work?

## Replies

### Reply by Pravesh Singh

Hi Ankit,

Based on the info you have provided all you have to do is just extract the row data from the datatable containing the logged in user.

## For example:

```
 //Extract data User objUser = new User(); objUser.Id = int.parse(dt.Rows[0]["ID"].ToString()); objUser.Login = dt.Rows[0]["Login"].ToString(); objUser.Password = dt.Rows[0]["Password"].ToString(); objUser.Type= int.parse(dt.Rows[0]["Password"].ToString());
```


---

Original Source: https://www.mindstick.com/forum/1782/how-to-get-logged-user-id-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
