PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

Defining PrimaryKey from multiple fields

 
 
Sam
Guest
Posts: n/a
 
      14th Jul 2005
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

Sam.

 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      14th Jul 2005
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)
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
defining cariables/fields =?Utf-8?B?TWFyYw==?= Microsoft Word Document Management 2 1st Sep 2006 05:46 PM
Defining data types for fields, when you a create a file mesut demir Microsoft VB .NET 11 10th Mar 2006 08:30 AM
Defining (or refining) Report Fields at runtime =?Utf-8?B?SmVmZiBIYXJiaW4=?= Microsoft Access Reports 3 6th Feb 2005 05:00 AM
Defining fields when creating a relationship =?Utf-8?B?RGF2aWQ=?= Microsoft Access Form Coding 1 3rd Jun 2004 06:33 AM
Defining Fields on a Table BBaggie Microsoft Access Database Table Design 3 25th Oct 2003 07:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.