Multiple data items in single field
Hi all - tried searching on this and did find several threads but not exactly what I was looking on - I might have had better luck with different wording :/ ah well
What I'm trying to do - VB 2005 express and sql 2005 express editions - Trying to set up just a basic hardware/software inventory program. As is I've got separate tables for computer and software licenses...with ComputerID and LicenseID primary keys respectively...where I'm bumping into walls is that I wanted to be able to link them together with a foreign key, for example the computer record would have a foreign key for LicenseID and when a license would get installed the ID would go in and there'd be a nice pretty link. However I run into scenarios where a computer might not have any software installed...or might have more than 1 software item. Or a single software item may be installed on 1 computer, multiple computers, or nowhere. It possible to have that single foreign key field link to multiple records from the opposite table?
What was originally suggested to me was to have a 3rd table called Installations. It'd have 3 rows...one named InstallationID as the primary key, and 2 foreign key rows named ComputerID and LicenseID that linked to the other tables, so that when a license was installed, a record would be added to the Installations table, and later on when we wanted to see where all a particular license was installed or what licenses a single computer had, the table could be filtered by computer ID or license ID and all matching records could be displayed. When I tried that out though I'm having a heck of a time getting the correct items to display.
Just as a basic test i set up a new form and dragged the tables onto it from the Data Sources window using "Details" view for each of them, so that it set up the table adapters and binding sources and navigator for me. I got rid of the auto-added labels + textboxes on the form and added just a couple new textboxes, 1 linked to the licenseID and one to another row i had in that table for productkey...tested it and it moves through the records fine and the correct data shows up in each box to correspond with the other. now though I'd like to add another control to display each of the ComputerIDs that are linked to the particular license being displayed in the other controls via the foreign keys routing through the Installations table, but I'm not having much luck.
im sure this very rough and hurried explanation has confused most readers by now :) hopefully the idea of what im trying to do got through at least. if so, has anyone come across something similar before that might have a suggestion or 2 of what a better way to go about it might be? Essentially I've got software records that need to have the option of being linked to either 0, 1, or multiple computer records and i need to find a way so that when i pull up the license record on my form, i can display a row from each of the computer records that it's linked to all at once (for example I want a list of all of the ComputerNames that are linked to that software record). Sorry again for the rough details but any help or tips are greatly appreciate! thanks for reading!
Re: Multiple data items in single field
The Installations table is definitely the way to do it - that makes it far simpler and more reliable (in terms of the database and your program) than the various alternatives I've seen over the years.
Unfortunately I can't help with the code etc in this case, as I don't use the drag-and-drop method, and don't have enough VB.Net experience to guide you as well as others can.