G
Guest
Hi.
A colleague of mine is trying to use an eight-byte array as the primary key into an ADO.NET DataTable, but he's getting exceptions thrown when he attempts to set the appropriate column as the primary key. Here's his sample:
Code:
public static void ByteArrayKey () {
DataTable dt = new DataTable();
dt.Columns.Add (new DataColumn("bytes",typeof(System.Byte[])));
DataRow dr = dt.NewRow();
dr["bytes"] = new System.Byte[] {0,1};
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["bytes"] = new System.Byte[] {1,0};
dt.Rows.Add(dr);
try {
dt.PrimaryKey = new DataColumn[]{dt.Columns[0]};
System.Console.WriteLine("Set primaryKey as byte array");
} catch (System.ArgumentException e) {
System.Console.WriteLine("Could not set primaryKey as byte array: {0}",
e.ToString());
}
}
This code will result in the exception being thrown. There *IS* a SqlDbType.Binary which is what we really want here, but I can't seem to find the appropriate System.Type to suggest as the DataColumn type to avoid the exception.
Anyone have ideas?
Thanks,
/s/ James
A colleague of mine is trying to use an eight-byte array as the primary key into an ADO.NET DataTable, but he's getting exceptions thrown when he attempts to set the appropriate column as the primary key. Here's his sample:
Code:
public static void ByteArrayKey () {
DataTable dt = new DataTable();
dt.Columns.Add (new DataColumn("bytes",typeof(System.Byte[])));
DataRow dr = dt.NewRow();
dr["bytes"] = new System.Byte[] {0,1};
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["bytes"] = new System.Byte[] {1,0};
dt.Rows.Add(dr);
try {
dt.PrimaryKey = new DataColumn[]{dt.Columns[0]};
System.Console.WriteLine("Set primaryKey as byte array");
} catch (System.ArgumentException e) {
System.Console.WriteLine("Could not set primaryKey as byte array: {0}",
e.ToString());
}
}
This code will result in the exception being thrown. There *IS* a SqlDbType.Binary which is what we really want here, but I can't seem to find the appropriate System.Type to suggest as the DataColumn type to avoid the exception.
Anyone have ideas?
Thanks,
/s/ James