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" 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" wrote in message


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

 > 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
Display posts from previous:   
Related Topics:
ADOX and Catalog and default field value - I am using VB6 and ADOX 2.7. I need to add a field (column) to a Catalog's Table's Column's collection with a default value. Is there a way to do this? I don't see it in the properties collection when it is instantiated nor when it has been appended t...

Recordset-adding to a Listview - I've got a weird problem - - - it must be something simple, but for the life of me, I must be missing it... I've got a recordset - and I'm trying to add the results into a listview, but, instead of adding each successive record after the first line of....

newbie - how to resize column MSFlexGrid - newbie - how to resize column MSFlexGrid I do not see in properties, maybe I am blind, how to change column width. I would like to set it to just resize automatically to widest field of the column, of corse. can I, may I!!!??? thanks -- Adam S

error converting the varchar value 'True' to a column of d.. - In a vb6 app using ado connecting to a sql server 2000 stored procedure, am seeing this error: "Syntax error converting the varchar value 'True' to a column of data smallint" The error only seems to happen when updating one record. Other reco...

Data Environment Designer - need additional table fields o.. - Hello -- There are too many columns in the table to fit on a form when dragging the DED's table's Command node onto the form. I need to add to the form some of those columns which did not come onto the form in that initial dragging. After dragging one...
   Database Help (Home) -> Visual Basic -> ADO All times are: Pacific Time (US & Canada)
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 ]