using System;
using System.Data ;
using System.Data.SqlClient ;namespace ConsoleApplication10
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
SqlConnection scnt = new SqlConnection (@"Data Source = (local) ; Integrated Security = SSPI ;" + "Initial Catalog = Northwind") ;
scnt.Open () ;
SqlDataAdapter sdat = new SqlDataAdapter ("SELECT 订单ID, 客户ID FROM 订单" , scnt ) ;
DataSet dset = new DataSet () ;
SqlCommandBuilder scbd = new SqlCommandBuilder ( sdat ) ;
SqlDataAdapter chansdat = new SqlDataAdapter ("SELECT * FROM 订单" , scnt ) ;
SqlDataAdapter dingsdat = new SqlDataAdapter ("SELECT * FROM 订单明细" , scnt ) ;
            chansdat.Fill (dset ,"订单") ;
dingsdat.Fill (dset ,"订单明细") ;
DataColumn[] keys = new DataColumn [1] ;
keys[0] = dset.Tables ["订单"].Columns ["订单ID"];
dset.Tables ["订单"].PrimaryKey = keys ;
DataRelation  drl = dset.Relations.Add ("chansdat" ,dset.Tables ["订单"].Columns ["订单ID"]  , dset.Tables ["订单明细"].Columns ["订单ID"]) ;
foreach (DataRow CustRow in dset.Tables ["订单"].Rows )
{
Console.WriteLine ("订单ID:" + CustRow["订单ID"] + CustRow["客户ID"]) ;
}
 
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
dset.Tables ["订单"].PrimaryKey = keys ;报错!
这些列当前不具有唯一直!
有人能和我说说什么意思.