PC Review


Reply
Thread Tools Rate Thread

abbreviated version please

 
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      20th Feb 2007
hey all,

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;

thanks,
rodchar
 
Reply With Quote
 
 
 
 
Tom Porterfield
Guest
Posts: n/a
 
      20th Feb 2007
rodchar wrote:
> hey all,
>
> 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]};
--
Tom Porterfield
 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      20th Feb 2007
thank you very much for the tip. rod.

"Tom Porterfield" wrote:

> rodchar wrote:
> > hey all,
> >
> > 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]};
> --
> Tom Porterfield
>

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      1st Mar 2007
dataTable.Columns[0]
I noticed you specified 0 and in the example i had a 1, is there a difference?

"Tom Porterfield" wrote:

> rodchar wrote:
> > hey all,
> >
> > 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]};
> --
> Tom Porterfield
>

 
Reply With Quote
 
Bobbo
Guest
Posts: n/a
 
      1st Mar 2007

rodchar wrote:

> dataTable.Columns[0]
> I noticed you specified 0 and in the example i had a 1


Not quite.

Your System.Data.DataColumn[1] explicitly specified the dimensions
DataColumns array, whereas this was implied in Tom's code by virtue of
the fact that only 1 column was passed to the constructor. (Somebody
correct me if I'm using duff terminology!)

Tom still refers to the same dataTable.Columns[0] that you did.

 
Reply With Quote
 
Tom Porterfield
Guest
Posts: n/a
 
      1st Mar 2007
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

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      1st Mar 2007
Thanks once again Tom and everyone for the help.

"Tom Porterfield" wrote:

> 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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Abbreviated (DOS) name in titles Terry Pinnell Windows XP General 13 11th Nov 2008 08:43 PM
Hyperlinks abbreviated? =?Utf-8?B?R2VvZmY=?= Microsoft Access 0 5th Sep 2006 02:51 PM
Abbreviated keystrokes =?Utf-8?B?RHIuIEo=?= Microsoft Outlook Discussion 0 13th Jan 2005 08:23 PM
Process Name Abbreviated? Powerguy Microsoft Windows 2000 1 7th Dec 2004 02:58 AM
Abbreviated indirect?? Dave R. Microsoft Excel Worksheet Functions 4 1st Apr 2004 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:30 PM.