Problem with MultiColumn Primary Key

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-17T15:33:55Z Indexed on 2010/03/17 16:11 UTC
Read the original article Hit count: 381

Filed under:
|
|
|
DataTable NetPurch = new DataTable();

DataColumn[] Acct_n_Prod = new DataColumn[2]; 
DataColumn Account;
Account = new DataColumn();
Account.DataType = typeof(string);
Account.ColumnName = "Acct";

DataColumn Product;
Product = new DataColumn();
Product.DataType = typeof(string);
Product.ColumnName = "Prod";

NetPurch.Columns.Add(Account);
NetPurch.Columns.Add(Product);

Acct_n_Prod[0] = Account;
Acct_n_Prod[1] = Product;

NetPurch.PrimaryKey = Acct_n_Prod;

NetPurch.Columns.Add(MoreColumns);

the code is based on the example here

When it is compiled and runs i get an error saying:

"Expecting 2 values for the key being indexed but received only one"

if I make Acct_n_Prod = new DataColumn[1]

and comment out the line adding product to the acct-n-prod array then it runs fine

I'm fairly new to this so I'm not sure where the error is

Thanks,

-Mike

© Stack Overflow or respective owner

Related posts about c#

Related posts about datatable