M
MB
Hello!
I wonder what is the best way to create a dataset for the table structure below and use it with a CheckBoxList.
Table structure
Contacts Events ContactEvents
ContID EventID _ContID
ContName EventName _EventID
Example of data
Contacts Events ContactEvents
230, Elvis Presley 13, Golf 230, 29
234, Bill Clinton 14, Soccer 234, 29
237, Stuart Graham 17, Hockey 234, 28
21, Basket 234, 17
28, Fotball 237, 13
29, Music 237, 14
In example above you can see, that Elvis likes Music. Bill likes Music, Fotball and Hockey. Stuart likes Golf and Soccer.
I have a CheckBoxList with all the Events where the user should be able to check or uncheck the different events. If I want to add Music event to Stuart my save function deletes all rows in ContactEvents with _ContID=237, return the CheckedItems, and inserts three new rows with _ContID=237. This doesn't seem to be the best solution. I don't get how to do this, and how to write the select query for the dataadapter to get all Events (so a commandbuilder can be used). I think I should be able to use less code and letting the components do the work?!?! The CheckBoxList has the Datasource property (and Displaymember/Valuemeber), but I can't find the benifits of using it.
Should I use another component?
Regards Magnus
I wonder what is the best way to create a dataset for the table structure below and use it with a CheckBoxList.
Table structure
Contacts Events ContactEvents
ContID EventID _ContID
ContName EventName _EventID
Example of data
Contacts Events ContactEvents
230, Elvis Presley 13, Golf 230, 29
234, Bill Clinton 14, Soccer 234, 29
237, Stuart Graham 17, Hockey 234, 28
21, Basket 234, 17
28, Fotball 237, 13
29, Music 237, 14
In example above you can see, that Elvis likes Music. Bill likes Music, Fotball and Hockey. Stuart likes Golf and Soccer.
I have a CheckBoxList with all the Events where the user should be able to check or uncheck the different events. If I want to add Music event to Stuart my save function deletes all rows in ContactEvents with _ContID=237, return the CheckedItems, and inserts three new rows with _ContID=237. This doesn't seem to be the best solution. I don't get how to do this, and how to write the select query for the dataadapter to get all Events (so a commandbuilder can be used). I think I should be able to use less code and letting the components do the work?!?! The CheckBoxList has the Datasource property (and Displaymember/Valuemeber), but I can't find the benifits of using it.
Should I use another component?
Regards Magnus