rodchar wrote:
>
>>> is there a shorter way to write the following:
>>>
>>> System.Data.DataColumn[] keys = new System.Data.DataColumn[1];
>>> // Add the column to the array.
>>> keys[0] = dataTable.Columns[0];
>>> // Set the PrimaryKeys property to the array.
>>> dataTable.PrimaryKey = keys;
>>
>> You could put it all on a single line.
>>
>> dataTable.PrimaryKey = new
>> System.Data.DataColumn[]{dataTable.Columns[0]};
>>
> dataTable.Columns[0]
> I noticed you specified 0 and in the example i had a 1, is there a
> difference?
Of course there is, but you're comparing two things that are not the same.
You initialized a new DataColumn array with a length of 1
(System.Data.DataColumn[] keys = new System.Data.DataColumn[1]

. You then
set the first element in that array to the first column in your table
(keys[0] = dataTable.Columns[0]

.
Since I initialized the array by the DataColumn array by giving it the
actual values to be stored in the array, I could leave the number of
elements off as it will automatically get initialized to the number of
elements between {}.
So the code is exactly the same as yours in what it does, just make sure you
are comparing the correct portion of your code to mine.
--
Tom Porterfield