简体   繁体   中英

How to insert data to a sql server relational database that involve primary and foreign keys in C#

I have a problem and really need your help. I have two inter-related tables which are: Persons(id(pk),first_name,last_name,age,address,gender_id(fk)). Genders(id(pk),gender_type). So by looking at these tables, you can see that the Genders table has a reference on the Persons table which is gender_id column. In my C# code, I have a gender combo box that fetches data from the Gender table(ie male and female). So what I want is when the user selects male, the male id should be save under the gender_id column in the Persons table like wise female. Any feedback will be highly appreciated.

You Have a dropdownlist which is filled from the genders table. drop down has a text which is set to gender_type and a value which is set to id of genders table. when the user selects a item in dropdownlist get the value of selected item and store in the Persons table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM