HighTechTalks DotNet Forums  

How can I programmaticaly add a column to a key.

VB.net microsoft.public.dotnet.languages.vb


Discuss How can I programmaticaly add a column to a key. in the VB.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Mr. X.
 
Posts: n/a

Default How can I programmaticaly add a column to a key. - 07-08-2010 , 10:26 AM






Hello.
I need to build a primary key (DataTable.primaryKey) programmatically,
but it has more then one column.
I didn't find any method for doing that.

How can I do that ?

Thanks

Reply With Quote
  #2  
Old   
Armin Zingler
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 12:30 PM






Am 08.07.2010 17:26, schrieb Mr. X.:
Quote:
Hello.
I need to build a primary key (DataTable.primaryKey) programmatically,
but it has more then one column.
I didn't find any method for doing that.

How can I do that ?
The type of DataTable.primaryKey is an array. An array can contain
more items.

--
Armin

Reply With Quote
  #3  
Old   
Mr. X.
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 12:53 PM



Yes, I know.

but I did something like this :
myTable.PrimaryKey = New DataColumn() {}
myTable.PrimaryKey.SetValue(New DataColumn("aKey"), 0)

.... and I get out of bounds on the second line.
What is the correct syntax?

Thanks


"Armin Zingler" <az.nospam (AT) freenet (DOT) de> wrote

Quote:
Am 08.07.2010 17:26, schrieb Mr. X.:
Hello.
I need to build a primary key (DataTable.primaryKey) programmatically,
but it has more then one column.
I didn't find any method for doing that.

How can I do that ?

The type of DataTable.primaryKey is an array. An array can contain
more items.

--
Armin

Reply With Quote
  #4  
Old   
Armin Zingler
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 02:24 PM



Am 08.07.2010 19:53, schrieb Mr. X.:
Quote:
Yes, I know.

but I did something like this :
myTable.PrimaryKey = New DataColumn() {}
myTable.PrimaryKey.SetValue(New DataColumn("aKey"), 0)

... and I get out of bounds on the second line.
What is the correct syntax?
myTable.PrimaryKey = New DataColumn() {firstcolumn, secondcolumn}

Otherwise you assign an empty erray and SetValue fails because
there is no space in the array.

--
Armin

Reply With Quote
  #5  
Old   
Mr. X.
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 03:24 PM



I don't know how much columns will be on first time, and I want dynamically
to change it (I don't know if there are two, or ten,
so {firstColumn, secondColumn} may not be the best solution.

Thanks

"Armin Zingler" <az.nospam (AT) freenet (DOT) de> wrote

Quote:
Am 08.07.2010 19:53, schrieb Mr. X.:
Yes, I know.

but I did something like this :
myTable.PrimaryKey = New DataColumn() {}
myTable.PrimaryKey.SetValue(New DataColumn("aKey"), 0)

... and I get out of bounds on the second line.
What is the correct syntax?

myTable.PrimaryKey = New DataColumn() {firstcolumn, secondcolumn}

Otherwise you assign an empty erray and SetValue fails because
there is no space in the array.

--
Armin

Reply With Quote
  #6  
Old   
Armin Zingler
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 03:31 PM



Am 08.07.2010 22:24, schrieb Mr. X.:
Quote:
I don't know how much columns will be on first time, and I want dynamically
to change it (I don't know if there are two, or ten,
so {firstColumn, secondColumn} may not be the best solution.
You can always assign a new array to the PrimaryKey property.


--
Armin

Reply With Quote
  #7  
Old   
Mr. X.
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 03:51 PM



The situation :
I am doing a loop, and each time I can add only one element to the
primaryKey,
so I must resize the array, without clearing it, but I don't know how to do
that.

Thanks

"Armin Zingler" <az.nospam (AT) freenet (DOT) de> wrote

Quote:
Am 08.07.2010 22:24, schrieb Mr. X.:
I don't know how much columns will be on first time, and I want
dynamically
to change it (I don't know if there are two, or ten,
so {firstColumn, secondColumn} may not be the best solution.

You can always assign a new array to the PrimaryKey property.


--
Armin

Reply With Quote
  #8  
Old   
Armin Zingler
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-08-2010 , 06:26 PM



Am 08.07.2010 22:51, schrieb Mr. X.:
Quote:
The situation :
I am doing a loop, and each time I can add only one element to the
primaryKey,
so I must resize the array, without clearing it, but I don't know how to do
that.
In the loop, collect the columns in a List(Of DataColumn).
After the loop, set the PrimaryKey to YourList.ToArray.



--
Armin

Reply With Quote
  #9  
Old   
Mr. X.
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-09-2010 , 01:25 AM



Thanks

"Armin Zingler" <az.nospam (AT) freenet (DOT) de> wrote

Quote:
Am 08.07.2010 22:51, schrieb Mr. X.:
The situation :
I am doing a loop, and each time I can add only one element to the
primaryKey,
so I must resize the array, without clearing it, but I don't know how to
do
that.

In the loop, collect the columns in a List(Of DataColumn).
After the loop, set the PrimaryKey to YourList.ToArray.



--
Armin

Reply With Quote
  #10  
Old   
Mr. X.
 
Posts: n/a

Default Re: How can I programmaticaly add a column to a key. - 07-09-2010 , 04:58 AM



One little problem.
MyTable.PrimaryKey = MyList.toArray
I got the exception : column must belong to a table.

"Armin Zingler" <az.nospam (AT) freenet (DOT) de> wrote

Quote:
Am 08.07.2010 22:51, schrieb Mr. X.:
The situation :
I am doing a loop, and each time I can add only one element to the
primaryKey,
so I must resize the array, without clearing it, but I don't know how to
do
that.

In the loop, collect the columns in a List(Of DataColumn).
After the loop, set the PrimaryKey to YourList.ToArray.



--
Armin

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.