Since I spent a few hours figuring this out, I figured
I'd post it for the record.
To add a composite (multiple column) primary key to an Access
database using ADOX and C#:
Table filesTable = new Table();
filesTable.Name = FILES_TABLE;
filesTable.Columns.Append(HOST_ID_COL, DataTypeEnum.adVarWChar, 100);
filesTable.Columns.Append(PATH_COL, DataTypeEnum.adVarWChar, 250);
filesTable.Columns.Append(PATH2_COL, DataTypeEnum.adVarWChar, 250);
filesTable.Columns.Append(NAME_COL, DataTypeEnum.adVarWChar, 200);
filesTable.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary,
HOST_ID_COL, null, null);
filesTable.Keys["PrimaryKey"].Columns.Append(PATH_COL,
DataTypeEnum.adVarWChar, 250);
filesTable.Keys["PrimaryKey"].Columns.Append(PATH_COL,
DataTypeEnum.adVarWChar, 250);
catalog.Tables.Append(filesTable);
There's the trick right there. Create the primary key specifying a
single column, then retrieve the key and add the additional columns.
It's so simple...
--Scott
Herfried K. Wagner [MVP] - 26 Jul 2004 02:42 GMT
* publicscott@comcast.net (Scooter) scripsit:
> To add a composite (multiple column) primary key to an Access
> database using ADOX and C#:
[quoted text clipped - 13 lines]
> DataTypeEnum.adVarWChar, 250);
> catalog.Tables.Append(filesTable);
Your question doesn't seem to be related to .NET Windows Forms
programming, so I suggest to post it to the ADO.NET group:
<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>
Web interface:
<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

Signature
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/