演示UniqueConstraint类的使用
2006-12-21 22:08
169 查看
(摘录自《C#函数实用手册》冶金工业出版社)
代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable testDT = new DataTable("student");
DataColumn testDC = new DataColumn("Id", Type.GetType("System.Int32"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("Name",Type.GetType("System.String"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("School",Type.GetType("System.String"));
testDT.Columns.Add(testDC);
DataColumn[] testDCA = new DataColumn[2];
testDCA[0] = testDT.Columns["Id"];
testDCA[1] = testDT.Columns["Name"];
UniqueConstraint testUC = new UniqueConstraint("IdNameConstraint",testDCA);
testDT.Constraints.Add(testUC);
foreach(UniqueConstraint uc in testDT.Constraints)
{
// 使用Equals方法判断当前的UniqueConstraint对象是否与指定对象相同
if (testUC.Equals(uc))
{
Console.WriteLine("识别到主键约束:" + testUC.ConstraintName);
Console.WriteLine("该约束的哈希代码:" + testUC.GetHashCode());
}
}
Console.ReadLine();
}
}
}
*****************************************
结果:
识别到主键约束:IdNameConstraint
该约束的哈希代码:37121646
代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable testDT = new DataTable("student");
DataColumn testDC = new DataColumn("Id", Type.GetType("System.Int32"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("Name",Type.GetType("System.String"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("School",Type.GetType("System.String"));
testDT.Columns.Add(testDC);
DataColumn[] testDCA = new DataColumn[2];
testDCA[0] = testDT.Columns["Id"];
testDCA[1] = testDT.Columns["Name"];
UniqueConstraint testUC = new UniqueConstraint("IdNameConstraint",testDCA);
testDT.Constraints.Add(testUC);
foreach(UniqueConstraint uc in testDT.Constraints)
{
// 使用Equals方法判断当前的UniqueConstraint对象是否与指定对象相同
if (testUC.Equals(uc))
{
Console.WriteLine("识别到主键约束:" + testUC.ConstraintName);
Console.WriteLine("该约束的哈希代码:" + testUC.GetHashCode());
}
}
Console.ReadLine();
}
}
}
*****************************************
结果:
识别到主键约束:IdNameConstraint
该约束的哈希代码:37121646
相关文章推荐
- C语言中预定义符 __FILE__, __LINE__, __FUNCTION__, __DATE__, __TIME__ 的使用演示
- 演示 zabbix LLD(Low-Level Discovery) 如何使用
- Java连接redis的使用演示样例
- 加载Properties配置的BeanFactory的使用演示
- 使用命令行控制 Windows 演示设置
- 【Gson】【2】Gson使用演示
- 演示: 使用静态NAT配置内部网络服务器提供对外服务能力 推荐
- 演示PropertyCollection类的使用
- 使用HADOOP演示MAPREDUCE配置总结
- Java 8 时间日期库的20个使用演示样例
- 实时时钟的演示:.毫秒级计时输出;串口输出速率:9600bps.中断的使用。
- 使用IMalloc接口来分配内存演示程序
- f2py::演示在python中如何使用Fortran代码
- f2py::演示Fortran二维数组在python中的使用示例
- 云打赏在博客中使用演示之CSDN博客
- cURL使用教程及实例演示
- Duang~Duang~Duang 还在使用jsfiddle和jsbin做在线前端代码展示和演示吗? 试试更强大的在线代码分享工具吧!
- SSL第三讲 SSL证书生成的超级工具的使用讲解和演示
- msdn daovidw 程序运行过程(分割多视图,演示CTreeView和CListView的使用)
- 使用BootStrap网格布局进行一次演示