forked from dotnet/dotnet-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.cs
87 lines (75 loc) · 2.64 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Data;
using System.Windows.Forms;
public class Form1: Form
{
protected DataSet DataSet1;
// <Snippet1>
private void GetConstraints(DataTable dataTable)
{
Console.WriteLine();
// Print the table's name.
Console.WriteLine("TableName: " + dataTable.TableName);
// Iterate through the collection and
// print each name and type value.
foreach(Constraint constraint in dataTable.Constraints )
{
Console.WriteLine("Constraint Name: "
+ constraint.ConstraintName);
Console.WriteLine("Type: "
+ constraint.GetType().ToString());
// If the constraint is a UniqueConstraint,
// print its properties using a function below.
if(constraint is UniqueConstraint)
{
PrintUniqueConstraintProperties(constraint);
}
// If the constraint is a ForeignKeyConstraint,
// print its properties using a function below.
if(constraint is ForeignKeyConstraint)
{
PrintForeigKeyConstraintProperties(constraint);
}
}
}
private void PrintUniqueConstraintProperties(
Constraint constraint)
{
UniqueConstraint uniqueConstraint;
uniqueConstraint = (UniqueConstraint) constraint;
// Get the Columns as an array.
DataColumn[] columnArray;
columnArray = uniqueConstraint.Columns;
// Print each column's name.
for(int i = 0;i<columnArray.Length ;i++)
{
Console.WriteLine("Column Name: "
+ columnArray[i].ColumnName);
}
}
private void PrintForeigKeyConstraintProperties(
Constraint constraint)
{
ForeignKeyConstraint fkConstraint;
fkConstraint = (ForeignKeyConstraint) constraint;
// Get the Columns as an array.
DataColumn[] columnArray;
columnArray = fkConstraint.Columns;
// Print each column's name.
for(int i = 0;i<columnArray.Length ;i++)
{
Console.WriteLine("Column Name: "
+ columnArray[i].ColumnName);
}
Console.WriteLine();
// Get the related columns and print each columns name.
columnArray = fkConstraint.RelatedColumns ;
for(int i = 0;i<columnArray.Length ;i++)
{
Console.WriteLine("Related Column Name: "
+ columnArray[i].ColumnName);
}
Console.WriteLine();
}
// </Snippet1>
}