i have made a Session which has as the EmailId as the session name....now i want to retrieve data in the user profile page ....which means the particular logged user will get to know their personal information....how do i do it???plz help
n.b:the database has 1 table only where EmailId is my primary key

Dani AI

Generated

Short answer: read the email value you stored in session, validate it, then run a parameterized query and map the returned row to the profile UI. and are right about using the session value and querying the database, but the thread is missing a few important safety and reliability steps.

Recommended steps

  1. Confirm the session value exists and is a valid email; if not, treat the request as unauthenticated and redirect to login.
  2. Use a parameterized command (never concatenate strings) to avoid SQL injection.
  3. Open the DB connection inside a using block so it is always disposed.
  4. Handle "no row found" explicitly (show a friendly message or log).
  5. Prefer storing a numeric user id in session instead of an email; it is smaller, faster, and stable if the user changes their email.
  6. Ensure session timeout and HTTPS are configured so credentials and session cookies are protected.

Minimal C# example (ASP.NET style)

// get session value
string email = Session["userEmail"] as string;
if (string.IsNullOrEmpty(email)) { Response.Redirect("Login.aspx"); return; }

string sql = "SELECT FirstName,LastName,Phone FROM Users WHERE Email = @email";
using (var conn = new SqlConnection(connectionString))
using (var cmd = new SqlCommand(sql, conn))
{
    cmd.Parameters.Add("@email", SqlDbType.NVarChar, 256).Value = email;
    conn.Open();
    using (var reader = cmd.ExecuteReader())
    {
        if (reader.Read())
        {
            lblName.Text = reader["FirstName"].ToString();
            // map other fields...
        }
        else
        {
            // no user found for that email
        }
    }
}

Troubleshooting notes

  • If nothing returns, confirm the session key name and the stored value (watch for trailing spaces/case).
  • Check connection string and DB user permissions.
  • Log exceptions server-side for diagnosis, and avoid revealing DB errors to users.
  • Consider using an ORM (Dapper/EF) if writing this pattern repeatedly.

Recommended Answers

All 2 Replies

I assume when you say you crated a Session that you mean you have stored their EmailID in teh session varaible.
If thats the case you will need to create a connection to your database and use a Select query to retreive rows where EmailID = Session["EmailID"].
Try reading this

retrive values from session and use it in query for accesing data simple yaar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.