一个主键没有问题!
但是假如我的DataTable有两个主键。ID1和ID2
那么传一个两个长度的对象数组过去(3,6),我的意思是找ID2=3并且ID1=13的
他怎么知道我的对应顺序了??
经过我的测试结果是
测试代码如下:
DataTable dt
=
new
DataTable();
DataColumn pkCol = new DataColumn( " ID " , Type.GetType( " System.Int32 " ));
pkCol.AutoIncrement = true ;
pkCol.AutoIncrementSeed = 1 ;
pkCol.AutoIncrementStep = 1 ;
dt.Columns.Add(pkCol);
dt.PrimaryKey = new DataColumn[] ... { dt.Columns.Add("Text2", Type.GetType("System.String")), dt.Columns.Add("Text1", Type.GetType("System.String")) } ;
int limit = 100 ;
int someNumber = limit;
DateTime startTime = DateTime.Now;
for ( int i = 1 ; i <= limit; i ++ )
... {
DataRow row = dt.NewRow();
row["Text2"] = i.ToString();
row["Text1"] = limit - i;
dt.Rows.Add(row);
}
DataRow dr = dt.Rows.Find( new Object[] ... { 55,45} );
StringBuilder aaa = new StringBuilder();
aaa.AppendFormat( " Text2:{0} Text1:{1} i:{1} <br/> " , dr[ " Text2 " ], dr[ " Text1 " ],dr[ " ID " ]);
dr = dt.Rows.Find( new Object[] ... { 45, 55 } );
aaa.AppendFormat( " Text2:{0} Text1:{1} i:{1} <br/> " , dr[ " Text2 " ], dr[ " Text1 " ], dr[ " ID " ]);
this .Response.Write(aaa.ToString());
DataColumn pkCol = new DataColumn( " ID " , Type.GetType( " System.Int32 " ));
pkCol.AutoIncrement = true ;
pkCol.AutoIncrementSeed = 1 ;
pkCol.AutoIncrementStep = 1 ;
dt.Columns.Add(pkCol);
dt.PrimaryKey = new DataColumn[] ... { dt.Columns.Add("Text2", Type.GetType("System.String")), dt.Columns.Add("Text1", Type.GetType("System.String")) } ;
int limit = 100 ;
int someNumber = limit;
DateTime startTime = DateTime.Now;
for ( int i = 1 ; i <= limit; i ++ )
... {
DataRow row = dt.NewRow();
row["Text2"] = i.ToString();
row["Text1"] = limit - i;
dt.Rows.Add(row);
}
DataRow dr = dt.Rows.Find( new Object[] ... { 55,45} );
StringBuilder aaa = new StringBuilder();
aaa.AppendFormat( " Text2:{0} Text1:{1} i:{1} <br/> " , dr[ " Text2 " ], dr[ " Text1 " ],dr[ " ID " ]);
dr = dt.Rows.Find( new Object[] ... { 45, 55 } );
aaa.AppendFormat( " Text2:{0} Text1:{1} i:{1} <br/> " , dr[ " Text2 " ], dr[ " Text1 " ], dr[ " ID " ]);
this .Response.Write(aaa.ToString());
这些代码很能说明事情的,就是说是按COLUMN的前后关系传数组的关系的。和我想像的一样