forked from dotnet/dotnet-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.cs
36 lines (32 loc) · 1.14 KB
/
source.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Data;
public class Sample
{
// <Snippet1>
public static void ConstraintAddRange(DataSet dataSet)
{
try
{
// Reference the tables from the DataSet.
DataTable customersTable = dataSet.Tables["Customers"];
DataTable ordersTable = dataSet.Tables["Orders"];
// Create unique and foreign key constraints.
UniqueConstraint uniqueConstraint = new
UniqueConstraint(customersTable.Columns["CustomerID"]);
ForeignKeyConstraint fkConstraint = new
ForeignKeyConstraint("CustOrdersConstraint",
customersTable.Columns["CustomerID"],
ordersTable.Columns["CustomerID"]);
// Add the constraints.
customersTable.Constraints.AddRange(new Constraint[]
{uniqueConstraint, fkConstraint});
}
catch(Exception ex)
{
// Process exception and return.
Console.WriteLine("Exception of type {0} occurred.",
ex.GetType());
}
}
// </Snippet1>
}