Click here to Skip to main content
15,921,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm developing a website Which contains profile of n no of peoples.
Here what the user will do is, he/she want to log in to view the peoples details.Only register user have the rights to view the details and he can view n no peoples details on one time login.
when ever the user click on the each profile its id should store in database.

In a database i have field called profileid.
1st time when user click on the profile means its id is getting stored in profileid.

What i want is when the same user click another profile id ,then it should store in same field with previous one with comma(,).

Eg:

profieid
20
20,15
20,15,10


This is my code:
C#
string Name = (string)(Session["Name"]);
        string time = (string)(Session["Time"]);
        string sql = ("UPDATE  History set RegID_UserProfile='" + Request.QueryString["id"].ToString() + "' WHERE UserName='" + Name + "' and LoginTime='" + time + "'");
        SqlCommand cmd7 = new SqlCommand(sql, con);
        int temp = cmd7.ExecuteNonQuery();
        if (temp == 1)
        {
            //aa
        }
        con.Close();



Likewise it should store..

Anyone have the idea to achieve this???
Posted
Updated 10-Mar-14 3:41am
v4
Comments
ZurdoDev 10-Mar-14 9:43am    
UPDATE History SET REgUD_UserProfile = RegID_UserProfile + ...

This way you add on to what is already there.
Just put a break point and see what is the dynamic query formed by code. Take that and execute it directly on Database. See if it is correct or not.

No, do not do it this way. It violates the first normal form[^] of relational database design. Every new profileid should go into a new row of its own, not concatenating with existing value. You should have 2 tables, say a users table and another profiles table (one-to-many relationship) like this:
Table: users
user_id (primary key)
user_name
[other fields]

Table: profiles
user_id (primary key and foreign key to user_id of users table)
profile_id (primary key)
[other fields]

When a user clicks on a profile, the user_id and the profile_id and other related information will be inserted as a new row once in the profiles table. The composite primary key of user_id and profile_id will ensures that no same pair of these values got inserted twice.
 
Share this answer
 
SQL
SELECT DISTINCT [Col1], [Col2],
[Col3] = STUFF ((SELECT ', ' + [Col3] FROM tbl_tempTable b
WHERE b.[Col1] = a.[Col1] FOR XML PATH('')), 1,2,'') 
FROM tbl_tempTable a

END
 
Share this answer
 
Comments
[no name] 11-Mar-14 0:47am    
Hi i just want to update the value in a single table called history and i dont want to view those thing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900