forked from dotnet/dotnet-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.cs
29 lines (27 loc) · 838 Bytes
/
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
using System;
using System.Data;
public class Form1
{
protected DataSet DataSet1;
// <Snippet1>
private void AddForeignConstraint(DataSet dataSet)
{
try
{
DataColumn parentColumn =
dataSet.Tables["Suppliers"].Columns["SupplierID"];
DataColumn childColumn =
dataSet.Tables["Products"].Columns["SupplierID"];
dataSet.Tables["Products"].Constraints.Add
("ProductsSuppliers", parentColumn, childColumn);
}
catch(Exception ex)
{
// In case the constraint already exists,
// catch the collision here and respond.
Console.WriteLine("Exception of type {0} occurred.",
ex.GetType());
}
}
// </Snippet1>
}