Dataset for specific table structure for CheckBoxList

  • Thread starter Thread starter MB
  • Start date Start date
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
 
Hi MB,

I would first retrieve all three tables into a dataset (or subset of them -
depends on what you need).
I would create a 4th, table:
ContId
EventId
EventName
Uses (bool)

And will populate it with cartesian product of Contacts x Events.
For the Uses I would set it to true whether ContactEvents contains it.

The so produced table I would link to CheckBoxList (using DataView for one
contact at a time perhaps).
After uses finishes editing the table, I would use the information in my
table to update the original three tables.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

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
 
Back
Top