I’ve lately been migrating from Delphi to C#. I find C sharp very powerful and the IDE is awesome. There are some unaccustomed stuff though.
On the database side I have two inner-related tables. Students and Categories. I keep CategoryID in the students table as foreign key. I want to link a DataGridView to the Students table.
When I add a new student I want to be ale to also choose the student’s Category from the dropdown list that list of available Categories. In Delphi we have an opportunity to add a lookup column to table so that it keeps CategoryID in the backgound but displays CategoryName.
How do I do it in C#? Is it possible through DataRelation? If yes, how?
… You don’t mention data technology (Linq etc.) or interface (e.g. Winforms, Webforms etc,) so it is far too hard to help you….
But I have done something similar and I would treat it as two queries, first do a
select category.nameto populate the drop down box, then something along the lines ofint _temp = select category.id where category.name == dropdownbox.selectedtextthen in your insert command for the student, you simply provide the int _temp.