Hi all,
I've narrowed down my problem to a key issue. If I don't create a key, then
ADO is happy. If I do, then I know get a complaint. I've whipped up the
code fragment below to illustrate my problem. I'm using ADO v2.8, although
v2.7 has the same problem.
Dim dbtblSQL as New ADOX.Table
Dim dbkeySQL as New ADOX.Key
With dbtblSQL
.Name = "New Table"
.Columns.Append "Col1", adInteger, 0
.Columns.Append "Col2", adInteger, 0
.Columns.Append "Col3", adInteger, 0
With dbkeySQL
.Name = "MyKey"
.Type = adKeyPrimary
.Columns.Append dbtblSQL.Columns("Col1") 'Problem line 1
.Columns("Col1").RelatedColumn = "Col1"
End With
.Keys.Append dbkeySQL
End With
Call dbcatSQL.Tables.Append(dbtblSQL)
VB6 now complains on problem line 1 stating "Object already in collection.
Cannot append", but If I don't "append", then the item really isn't in the
collection.
The question boils down to how to create a primary key related to a column
in a table, where the column already exists. Thanks in advance.
Martin A. Weinberger
ButterflyVista
http://www.butterflyvista.com/
(when responding to me by email, remove the "X_" from the beginning)
Hi Again,
I also tried the single line method. The code below still produces a "The
parameter is incorrect."
objTable.Columns("PrimaryKey_Field").Properties("A utoIncrement").Value =
True
objTable.Keys.Append "PrimaryKey", adKeyPrimary, "PrimaryKey_Field"
Martin A Weinberger
ButterflyVista
Please remove the x_ to send me an email directly.
|||I found the problem thanks to some outside help. :-) The problem turned out
to be that when you use the AutoIncrement attribute, you must append the
table before you can create keys on it. This little MS ommission cost me a
few days, but at least I learnt something, so I thought that I pass it on.
Martin A Weinberger
ButterflyVista
Please remove the x_ to send me an email directly.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment