Inserting checkbox values into one field

Discussion in 'ASP.NET Code Snips' started by ebosysindia, May 8, 2009.

  1. ebosysindia

    ebosysindia Guppy


    I have a checkboxes on my page (.aspx) like

    checkbox1 - item1
    checkbox2 - item2
    checkbox3 - item3

    what i want is that when a user selects certain checkboxes
    they should be inserted into a table called
    customer which has fields (customer id and actions)

    the data should be inserted as

    customerid actions
    1 item1,item2,item3
    2 item1,item3
    3 etc..

    i.e all the values should be inserted into database into one field separated by commas.

  2. SubSpace

    SubSpace Bass

    This is not really the forum to ask questions, but just concatenate the strings and update the database in one of the many ways ADO.NET offers you :)

    ...however. Depending on what you're trying to accomplish, it's not a good idea to put these values into a single field at all. It would probably be better to store them in a second table and have a one-to-many relation between those two tables. Moreover, you might want to put the actions themselves into the database as well.


    This would be the way to go if you actually had to do stuff with the information :) Putting all the values into a single text field makes it harder to work with when you want to retrieve information. Not only that, your queries will be much slower than they could have been with the right table structure, indexes and statistics.

    It wasn't my intention to confuse you or anything, but I think it would be good to find some basic database and ADO.NET tutorials to get you started. And if you were thinking about it, forget about Microsoft Access and skip straight to MS SQL Server :)

Share This Page

JodoHost - 26,000 hosting end-users in 100 countries
Plesk Web Hosting
VPS Hosting
H-Sphere Web Hosting
Other Services