Quantcast
Channel: Foro de SQL Server Data Access
Viewing all articles
Browse latest Browse all 158

Multi Column Primary Key's in Access using ADOX [c#]

$
0
0

Hi all,

I have been pulling my hair trying to figure out what the guys at microsoft were thinking when creating the ADOX library. I have an access table that is syncronized with a SQL server. The table has a primary key with two columns [User] and [Program]. The SQL Server has both columns in as the primary key columns and I have a syncronization mechanism that is responsible for several things, one of which is to recreate the Access data structure. All works well for all tables except this one. I have tried to create the multi-column key in several ways, none that worked. Let me show you what I am doing:

 

 

CatalogClass

catDCDLocal;

Column c;

catDCDLocal =

newCatalogClass();

catDCDLocal.let_ActiveConnection(

dbAccess.buildConnectionString(Settings.CattDCDLocalPath, Settings.SecurityDBPath, s.UserID, s.Password));

 

foreach (Table tbl in catDCDLocal.Tables) {  

   if (tbl.Name == "Users") {     

/* This is retarded so need to clean up... Users table has a primary key consisting of 2 columns */

for (int i = tbl.Keys.Count - 1; i >= 0; i--) { //remove the keys

tbl.Keys.Delete(i);

}

for (int i = tbl.Indexes.Count - 1; i >= 0; i--) {  //remove the indexes

tbl.Indexes.Delete(i);

}

tbl.Keys.Append(

"PrimaryKey", KeyTypeEnum.adKeyUnique, "User", "", "");

tbl.Keys[0].Columns.Append("Program", DataTypeEnum.adWChar, 6);

   }

}

 

I have also tried:

tbl.Keys.Append(

"PrimaryKey", KeyTypeEnum.adKeyUnique, "User", "", "");

//tbl.Keys[0].Columns.Append("Program", DataTypeEnum.adWChar, 6);

Key k = tbl.Keys[0];

Column col = tbl.Columns["Program"];

//col.ParentCatalog = catDCDLocal;

k.Columns.Append(col,

DataTypeEnum.adWChar, 6);

 

 

 

Nothing works for me ;-(

 


Viewing all articles
Browse latest Browse all 158

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>