Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir If i want to store the list-box selected items into one column(i.e interests) of table where already few records are there like username, id,city,country and i want to add one more column i.e interests(which is a list-box) and user who is logged in when select some interests .i want it to be added in that interest column for a particular user, and in a separate row.


I have tried, the interests that user is selecting from list-box is storing in a table.But it not for the logged in user.It is displayed on the next row with all the other columns as Null values.My table looks like this:

UserName       Id      city     country   pin-code       interests
NULL           NULL    NULL     NULL      NULL           privacy,protection 



instead I want all the above user fields as the logged on user details.
Posted
Updated 22-Apr-15 19:58pm
v2
Comments
Gideon van Dyk 22-Apr-15 21:13pm    
A segment of the code used to try and persist the data to the DB will aid in getting a clearer answer.

Don't store interests as comma separate values.
Store each interest as a new row.

This is known as first normal form[^] during normalization of a relational database.
 
Share this answer
 
v2
I have written code like this, it stores the listbox items for particular user, but it is updating the items in listbox.Like when i select 2 items....for eg: privacy, php its showing only php....i.e the current selected item....



SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);

SqlCommand cmd = conn.CreateCommand();
C#
foreach(ListItem item in ListBoxadditems.Items) // to store the values of listboxitems into database as per logged in user
            {

SQL
conn.Open();
                   cmd.CommandText ="UPDATE UserData SET Interests='"+item.Text+"' WHERE UserName='"+Session["New1"]+"'";

C#
cmd.ExecuteNonQuery();
                         Label5.Text = "Data Inserted";
                         conn.Close();

}
 
Share this answer
 

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