On 14 Jul 2005 09:49:36 -0700, "Sam" <(E-Mail Removed)> wrote:
¤ 1. I'm creating an Access database on the fly using ADOX via COM
¤ Interop.
¤
¤ 2. I create a CatalogClass, create TableClass and append ColumnClass to
¤ the table as required.
¤
¤ 3. In one such table, I have two text fields (adVarWChar) called
¤ "CutterID" and "Material".
¤
¤ 4. I want to define a primary key consisting of both the columns taken
¤ together, i.e. the combination of CutterID and Material is to be unique
¤ for each record.
¤
¤ 5. To do so I used the sample on
¤
http://support.microsoft.com/default...b;en-us;252908
¤
¤ 6. My code looks as follows-
¤
¤ // Have to use the ADOX.Key object
¤ ADOX.KeyClass key = new ADOX.KeyClass();
¤ key.Name = "PrimaryKey";
¤ key.Type = ADOX.KeyTypeEnum.adKeyPrimary;
¤
¤ // These columns have been appended to the tbl before calling this
¤ key.Columns.Append ("CutterID", ADOX.DataTypeEnum.adVarWChar, 0);
¤ key.Columns.Append ("Material", ADOX.DataTypeEnum.adVarWChar, 0);
¤
¤ // THE NEXT LINE CHOKES
¤ tbl.Keys.Append (key , ADOX.KeyTypeEnum.adKeyPrimary, "", "", "");
¤
¤ 7. The tbl.Keys.Append call throws exception "Exception from HRESULT:
¤ 0x800A0BB9." which means "adErrInvalidArgument:The arguments are of the
¤ wrong type, are out of acceptable range, or are in conflict with one
¤ another." (see
¤
http://msdn.microsoft.com/library/de...erty_oledb.asp)
¤
¤ 8. Help with the tbl.Keys.Append syntax please. I've tried every
¤ permutation & combination.
¤
¤ 9. Thanks
I would recommend using Access SQL DDL instead of ADOX to create your table schema:
Fundamental Microsoft Jet SQL for Access 2000
http://msdn.microsoft.com/library/de.../acfundsql.asp
Paul
~~~~
Microsoft MVP (Visual Basic)