I know that there are a lot of possible solutions to set up a working mechanism to get working databases and windows forms and all the problems we find between it, like relations, bindings and so on.
I have chosen just one possiblity to learn a bit more how i can go on with c# in .Net and databases. As my project is a very small one i needed a very fast and easy possiblity, that is why i thought hey, try using standard ADO.NET with an simple database provider.
And i went fast and good with it, as there are many tutorials and samples out there. But when I came to the point of relations the only thing developer seem to do is to bind them with an dataGridView or dataView. The most use Visual Studio that makes it rather simple with its design-time GUI.
I'm working on an simple app without an Grid, but an TreeView and with detailed views, one to show, one to edit. So this detail views are populated with labels to show the data and textboxes to edit the data.
So, binding a simple column from a table in dataset to an textbox is easy and works fine. But what if the column is a relation to an other table, so you will find only the id in it, how do I get the name or an other field of the related table?
I have done the relation why doesn't it show up the field i like?
Here is the solution after a lot of days and nerves...and it is so simple that i can't understand to have found it in any other tutorial else where.
MasterSource = new BindingSource(RatingsDataset, GenresTable);
DetailsSource = new BindingSource(MasterSource, "rel_GamesGenre");
Here I set an binding between the Games and Genres Data.
What happens is, when record of Games changes the Genres will point
to the record of the foreignKey relation that i set before.
Thas is all. The binding to a field of Genres for the label will look like this:
GenreText.DataBindings.Add("Text", RatingsDataset, GenresTable + ".name");
Without the BindingSource the Genres would point to the first record in the table.
Thanks to Espen who tried to help me out.
Regards