Results 1 to 2 of 2
2004-05-02, 08:40 #1
- Join Date
- Mar 2001
- Dudley, Midlands, England
- Thanked 0 Times in 0 Posts
Dataenvironment & multiple child levels (VB6 sp5)
Hope someone can help point me in the right direction. This is what I'm trying to do:
I've got three tables containing related data: Programme, Season and Episode. Programme has a one-to-many relationship with Season, and Season has a one-to-many relationship with Episode. Each table contains a unique key which is used as a foreign key on the other side of the 1-M relationship. I'm pretty sure I've got my data structure as I need it.
I want to display this data in a single form. The top 20% or so of the form showing details of a single selected Programme. The next 20% or so showing details of a single selected Season. The remaining showing, in some kind of grid, a list of episodes for the selected season.
This is what I've got so far:
I've created a data environment with one connection and that connection has a command (cmdProgrammeData) which returns a set of programme details. I've also created a child command (cmdSeasonData) which returns data for the season and which is related to cmdProgrammeData by means of the Programme's unique ID. I then created another child command (a grandchild, if you like) called cmdEpisodeData which is related to cmdSeasonData by the season's unique ID.
On the form, I've got a number of controls bound to fields from command cmdProgrammeData and a separate unbound combobox from which I can select which programme I want to look at. Similarly there are a number of controls bound to fields from command cmdSeasonData and a separate unbound combobox from which I can select the season (of that programme) which I'm interested in. Finally, there's a grid bound to cmdEpisodeData.
I can select an item in the programme combo and in a few lines of code, this repositions the programme recordset and this is reflected by the appropriate values appearing in the controls bound to the programme command, so I know this bit's working OK. Also, this is reflected in the data contained in the controls bound to the season command as these change too.
Where I'm baffled is this: when I update the programme combo, I can reference a recordset (rscmdProgrammeData) and by changing my current record in this recordset, I automatically change the record which the bound controls are showing. But for seasons, the same thing doesn't happen. So what do I need to do instead?
Because it's a child command, I don't get a recordset object created in the same way. I know that the programme recordset returns (as a field) a recordset object for the season data, but although I can easily change my position in this recordset (by Move or Find methods, for example), this isn't reflected in the form's bound fields which continue to display whatever was in the first season record for the current programme.
So... am I just missing something really obvious, doing something really dumb, or tackling this in the wrong way altogether?
2004-05-02, 18:01 #2
- Join Date
- Aug 2001
- Evergreen, CO, USA
- Thanked 65 Times in 64 Posts
Re: Dataenvironment & multiple child levels (VB6 sp5)
I'll take a whack at this, though I am an Access developer rather than a VB developer. (In Access we use what are called subforms, which manage all this stuff for us very nicely, and with virtually no code.) Taking your approach, I believe you are going to have to close and reopen the recordset for any bound controls, or alternatively display all the data in unbound controls. Doing this sort of thing in VB is not a trivial exercise, especially when you get parent - child - grandchild relationships such as you have. In a nutshell, you have to change the SQL statements behind the recordsets so that you restrict the data to the subset of the table that you are trying to display. Hope this helps.Wendell