Welcome to dbFreaks.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Adding a column to an existing ADOX Catalog's table's key

 
   Database Help (Home) -> Visual Basic -> ADO RSS
Next:  VB6 using ADO, sproc with return recordset  
Author Message
Wart

External


Since: Jul 28, 2004
Posts: 7



(Msg. 1) Posted: Thu Feb 17, 2005 5:40 pm
Post subject: Adding a column to an existing ADOX Catalog's table's key
Archived from groups: microsoft>public>vb>database>ado (more info?)

Does anyone know how (or whether it is possible) to add a column to an
existing key for a column using ADOX?

pseudo code:
Dim cn as ADODB.Connection
Dim lCat as new ADOX.Catalog
Dim ltbl as new ADOX.Table
Dim lKey as New ADOX.Key

'open the cn

Set lCat.ActiveConnection = cn
Set ltbl = lCat.Table("Table1")
Set lKey = ltbl.Key("Primary_Key")

'At this point, if there is one column as the primary key for Table1 then
'lKey.Columns.Count will = 1
lKey.Columns.Append "SomeField"

'At this point, the lKey.Columns.Count will still = 1

If you add a new key, you can add as many columns as you want and the count
will incriment as you do so.
So, do I have to delete the key and readd it or is there another way to do
this through ADOX?
Thanks,
CF

 >> Stay informed about: Adding a column to an existing ADOX Catalog's table's key 
Back to top
Login to vote
Paul Clement

External


Since: Sep 02, 2003
Posts: 236



(Msg. 2) Posted: Fri Feb 18, 2005 11:06 am
Post subject: Re: Adding a column to an existing ADOX Catalog's table's ke [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 17 Feb 2005 16:56:41 -0500, "Wart" <nospamWart RemoveThis @epix.net> wrote:

¤ Does anyone know how (or whether it is possible) to add a column to an
¤ existing key for a column using ADOX?
¤
¤ pseudo code:
¤ Dim cn as ADODB.Connection
¤ Dim lCat as new ADOX.Catalog
¤ Dim ltbl as new ADOX.Table
¤ Dim lKey as New ADOX.Key
¤
¤ 'open the cn
¤
¤ Set lCat.ActiveConnection = cn
¤ Set ltbl = lCat.Table("Table1")
¤ Set lKey = ltbl.Key("Primary_Key")
¤
¤ 'At this point, if there is one column as the primary key for Table1 then
¤ 'lKey.Columns.Count will = 1
¤ lKey.Columns.Append "SomeField"
¤
¤ 'At this point, the lKey.Columns.Count will still = 1
¤
¤ If you add a new key, you can add as many columns as you want and the count
¤ will incriment as you do so.
¤ So, do I have to delete the key and readd it or is there another way to do
¤ this through ADOX?


AFAIK, you have to drop (delete) the existing primary key and create a new one. I'm not aware of any
way to *modify* an existing primary key through ADOX, since you add the columns to the Key object
first and then add it to the Keys collection.


Paul ~~~ pclement RemoveThis @ameritech.net
Microsoft MVP (Visual Basic)

 >> Stay informed about: Adding a column to an existing ADOX Catalog's table's key 
Back to top
Login to vote
Wart

External


Since: Jul 28, 2004
Posts: 7



(Msg. 3) Posted: Tue Feb 22, 2005 3:39 pm
Post subject: Re: Adding a column to an existing ADOX Catalog's table's ke [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Paul,
Thanks for the reply. That is the conclusion/solution I went with.
CF

"Paul Clement" <UseAdddressAtEndofMessage.TakeThisOut@swspectrum.com> wrote in message
news:jd4c119lt5bmlh5v0grinorgkn76duee5a@4ax.com...
 > On Thu, 17 Feb 2005 16:56:41 -0500, "Wart" <nospamWart.TakeThisOut@epix.net> wrote:
 >
 > ¤ Does anyone know how (or whether it is possible) to add a column to an
 > ¤ existing key for a column using ADOX?
 > ¤
 > ¤ pseudo code:
 > ¤ Dim cn as ADODB.Connection
 > ¤ Dim lCat as new ADOX.Catalog
 > ¤ Dim ltbl as new ADOX.Table
 > ¤ Dim lKey as New ADOX.Key
 > ¤
 > ¤ 'open the cn
 > ¤
 > ¤ Set lCat.ActiveConnection = cn
 > ¤ Set ltbl = lCat.Table("Table1")
 > ¤ Set lKey = ltbl.Key("Primary_Key")
 > ¤
 > ¤ 'At this point, if there is one column as the primary key for Table1
 > then
 > ¤ 'lKey.Columns.Count will = 1
 > ¤ lKey.Columns.Append "SomeField"
 > ¤
 > ¤ 'At this point, the lKey.Columns.Count will still = 1
 > ¤
 > ¤ If you add a new key, you can add as many columns as you want and the
 > count
 > ¤ will incriment as you do so.
 > ¤ So, do I have to delete the key and readd it or is there another way to
 > do
 > ¤ this through ADOX?
 >
 >
 > AFAIK, you have to drop (delete) the existing primary key and create a new
 > one. I'm not aware of any
 > way to *modify* an existing primary key through ADOX, since you add the
 > columns to the Key object
 > first and then add it to the Keys collection.
 >
 >
 > Paul ~~~ pclement.TakeThisOut@ameritech.net
 > Microsoft MVP (Visual Basic)<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Adding a column to an existing ADOX Catalog's table's key 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Visual Basic -> ADO All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]