boris
boris

Reputation: 353

Foreign key in C#

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

Answers (1)

Mukesh Kalgude
Mukesh Kalgude

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

Related Questions