Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi....
is this possible to store 2 or more selected check-box values in same column in data base.i am using asp.net 3.5 and sql 2005..

Actually i want to say that if select one check-box then it stored in one column in database but if i select multiple check-box at one time then also its value should stored in same column....
please help me out........
thanks
Posted

What you are doing is not quite correct.
You should ideally be storing all the values of the list in a table.

Based on what the user chooses, we should save a key and all the values selected as separate rows in a table used for tracking what the user has selected.

Saving items in a concatenated format violates first normal form.
 
Share this answer
 
v3
CheckBoxList
Yes you can use a delimiter and append all the selected values and insert into single database column. Split using the delimiter while retrieving from database.

[update]
C#
StringBuilder sb = new StringBuilder();
           foreach (ListItem item in CheckBoxList1.Items)
           {
               if (item.Selected == true)
               {

                   sb.Append(item.Text + "|");
               }
           }
           //Response.Write(sb.ToString());
           //insert the sb value into the database

[/update]
 
Share this answer
 
v2
Comments
vivek_cool 4-Aug-11 1:29am    
hey thanks.. for your reply but how we can do that ca u please tell me brifly
m@dhu 4-Aug-11 1:38am    
I have updated the solution with code check it.
Abhinav S 4-Aug-11 1:56am    
Reasonable solution. 5. No need to downvote it at all.
But what the user is doing violates the first normal form.
m@dhu 4-Aug-11 2:09am    
But what the user is doing violates the first normal form.
That explains it. Thanks.
vivek_cool 4-Aug-11 5:13am    
k i get it thanks and By the way we can also used Comma separator also na

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