Olá Senhores..
á pesquisei antes de postar esta dúvida , porém não me atenderam .Eu quero usar o método FIND do DataRow ,e para isso preciso definir um primaryKey na DataTable. Essa DataTable é alimentada direto por um retorno do Banco, tendo portanto o nome das colunas
iguais as do Banco,
ex: Coluna CODPRODUTO
TENTEI :
dt.PrimaryKey = new DataColumn() {dt.Columns["CODPRODUTO"]};
erro:
Cannot initialize type 'System.Data.DataColumn' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
NO PRÓPRIO POST SUGERIDO PELO FORUM , EXISTE UM EXEMPLO:
private void SetPrimaryKeys()
{
// Create a new DataTable and set two DataColumn objects as primary keys.
DataTable table = new DataTable();
DataColumn[] keys = new DataColumn[1];
DataColumn column;
// Create column 1.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName= "FirstName";
// Add the column to the DataTable.Columns collection.
table.Columns.Add(column);
// Add the column to the array.
keys[0] = column;
// Create column 2 and add it to the array.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "LastName";
table.Columns.Add(column);
// Add the column to the array.
keys[1] = column;
// Set the PrimaryKeys property to the array.
table.PrimaryKey = keys;
}
Desta Forma eu teria que formatar a DataTable , com tipo e nomes de coluna.Mas eu não preciso disso , eu apenas recebo direto do banco.Será que deu para entender ??
Obrigado.