S
Scooter
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
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