I have an ASP.NET form that stores it's data in MSDE but I just added a multi-select ListBox to the form and I'm having a hard time coming up with a way of writing that data to the database. Should I write the values into a column on the same table where I store the rest of the data from the form (values separated by a comma) or shouild I create another table (one to many) and store the data there. I like the second option, but I'm not sure how to loop through each value and write it to the database table.
I grab the values for the selection as follow:
foreach (ListItem lstItem in lbAttendees.Items)
{
if (lstItem.Selected == true)
{
grpList.Add(lstItem.Value.ToString());
}
}
but I'm not sure on what to do next and could use some help.
Thanks
Germanoshouldn't lbAttendees have .SelectedItems?
Next, you should be passing the values to the database through sql or other dataaccess means.|||>>Should I write the values into a column on the same table where I store the rest of the data from the form (values separated by a comma) or shouild I create another table (one to many) and store the data there.
I would strongly suggest option 2 (Normalize).
>>I'm not sure how to loop through each value and write it to the database table.
Well you have some options.
i) Loop through your items on the client and perform inserts (one row at a time).
ii) Package up the values as an xml chunk and use openxml to insert (set based method, less chatty)
ii) Package up the values as a delimited string and perform parsing and insert at the server.
And there are others (using OO: collections, persistance frameworks mechanisms, etc..)sql
No comments:
Post a Comment