How do i associate a particular information such as Picture or comments to a logged in User. I want to do it such that when a particular user is logged in, it displays his or her pictures or albums and comments associated with his account. but i dont seem to be getting it. Please help me out, its urgent.

Dani AI

Generated

A concise, practical flow that ties the replies together: persist the account primary key across requests (authentication ticket or session), store each image row with that UserId in the database, and fetch only rows that match the active account. pointed toward tracking identity and asked for code — below is a minimal, safe example showing schema, how the login side persists an id, and how an album page queries and binds the results.

SQL schema and retrieval (minimal):

CREATE TABLE Users (
  UserId INT IDENTITY(1,1) PRIMARY KEY,
  Username NVARCHAR(100) NOT NULL
);

CREATE TABLE UserPictures (
  PictureId INT IDENTITY(1,1) PRIMARY KEY,
  UserId INT NOT NULL REFERENCES Users(UserId),
  FileName NVARCHAR(255) NOT NULL,
  Caption NVARCHAR(255) NULL
);

SELECT PictureId, FileName, Caption
FROM UserPictures
WHERE UserId = @UserId
ORDER BY PictureId DESC;

Example ASP.NET (C#) snippets:

// after successful authentication
Session["UserId"] = foundUserId;

// on album page
int userId = Session["UserId"] != null ? Convert.ToInt32(Session["UserId"]) : 0;
using(var cn = new SqlConnection(connString))
using(var cmd = new SqlCommand("SELECT PictureId, FileName, Caption FROM UserPictures WHERE UserId=@UserId", cn))
{
  cmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;
  var dt = new DataTable();
  new SqlDataAdapter(cmd).Fill(dt);
  Repeater1.DataSource = dt;
  Repeater1.DataBind();
}

Common causes of "no data records": the session value is missing or wrong, the UserId used does not exist in UserPictures, the query parameter is not set, the connection string points to a different database, or the image filenames/paths are incorrect. Check session value early, log the parameter sent to SQL, verify rows exist for that UserId, and ensure DataBind is called. Security note: always use parameterized queries and avoid exposing raw file paths; consider serving images through a handler that validates the requesting account.

Recommended Answers

All 3 Replies

Hi

This is very simple just store user identity(eg userid) in session and every time get the data associated with user from database or in case you are working with file's like images just store the file name in database in association with user.

It tells me "there are no data records to display".Can you show me a little example of creating a session that is associated with data to be displayed.

It would help if we could see any examples of the code you are using?

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.