简体   繁体   English

需要在单列中存储多个用逗号分隔的值

[英]Need to store multiple values seperated by comma(,) in single column

I'm developing a website Which contains profile of n no of peoples. 我正在开发一个网站,其中包含n个民族的个人资料。 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. 每当用户单击每个配置文件时,其ID都应存储在数据库中。

In a database i have field called profileid. 在数据库中,我有一个称为profileid的字段。 1st time when user click on the profile means its id is getting stored in profileid. 第一次,当用户单击配置文件时,表示其ID已存储在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(,). 我想要的是当同一用户单击另一个配置文件ID时,那么它应该与上一个使用逗号(,)存储在同一字段中。

Eg: 例如:

profieid 20 20,15 20,15,10. profieid 20 20,15 20,15,10。

Likewise it should store.. 同样,它应该存储..

Here is my update query 这是我的更新查询

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();

Anyone have the idea to achieve this??? 任何人都有实现这一目标的想法???

Changing the following line in your code would help you achieve what you want: 更改代码中的以下行将帮助您实现所需的目标:

string sql = ("UPDATE  History set RegID_UserProfile=RegID_UserProfile + ',' + '" + Request.QueryString["id"].ToString() + "' WHERE UserName='" + Name + "' and LoginTime='" + time + "'");

But now a piece of advice, what you are doing and the way you are doing is immencely outdated, haveing too many flaws and secutiry vulnerabilities. 但是,现在有一条建议, 您正在做什么以及您的工作方式已经过时,存在太多的缺陷和安全漏洞。 You should look for new methods of db access. 您应该寻找新的数据库访问方法。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM