Reputation: 353
I have two tables, A and B, in a dataset in SQL Server; I have created a connection to the dataset in a c# project in visual studio. How can I create a foreign key ( A is the parent) between my two tables ? I want to create the foreign key in visual studio and that it is visible in SQL server.
Upvotes: 0
Views: 1888
Reputation: 4844
You want create relationship in two table Refer this link
http://www.c-sharpcorner.com/Blogs/5608/create-a-relationship-between-two-dataset-tables.aspx
Code from the linked article:
DataSet objDS = new DataSet();
objDS.Tables.Add(Employee);
objDS.Tables.Add(Department);
DataRelation objRelation = new DataRelation("objRelation",
Employee.Columns["EmpID"], Department.Columns["EmpID"]);
objDS.Relations.Add(objRelation);
Upvotes: 2