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 :(
Loading
Sandeep Singh ShekhawatPosted Jun 5, 2013, 10:08 PM
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"];
}