Skip to content

Geting LogedIn User Data

John Joe

Asked Jun 5, 2013, 10:43 AM EDT1 answer
Share
LinkedInX
Hello, I need Help... I want to get Login User Information from SQL Table...

I have two tables which are Login and StudentInfo *  all have studentID.

How do I get all the Information in StudentInfo Table and display it for a current logedin user  in C#

I have used session to display loged in username but I dont know how to display other information.


Please Help :(


 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sandeep Singh Shekhawat
    0
    Hi John,

    Follow these steps

    1. Get studentId  from login table when you are getting username.
    2. Create another session variable studentId, as you are creating for username.
    3. When you want logged in user information  get studentId session variable on that page.
    4. Convert studentId session variable in intger varaiable.like

            int studentId = Convert.ToInt32(Session["studentId"]);
    5. Pass this studentId to query for get logged in user information for StudentInfo table. like

            int studentId = Convert.ToInt32(Session["studentId"]);
     
         string conStr = "Data Source=sandeepss-PC;Initial Catalog=Tutorial;User                            ID=sa;Password=********";
       string str = "Select * From StudentInfo  WHERE studentId=" + studentId;
     
      using (SqlConnection con = new SqlConnection(conStr))
      {
              if (con.State == ConnectionState.Closed)
                      con.Open();
     
              SqlDataAdapter dap = new SqlDataAdapter(str, con);
              DataSet ds = new DataSet();
              dap.Fill(ds, "StudentInfo");
     
             //Here logged in user data
              DataTable dt = ds.Tables["StudentInfo"];
      }
    0