Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Access Table with Primary Key in ADOX

Status
Not open for further replies.

snobrdinrtiste

Programmer
Aug 22, 2005
24
US
Can someone help me with this... i'm stumped
how can I add a primary key to an Access table I created using ADOX.

here's my code:

ADODB.Connection sqlconAdo = new ADODB.Connection();
ADOX.Catalog sqlcatAdox = new ADOX.Catalog();
ADOX.Table sqltableAdox = new ADOX.Table();
ADOX.Key sqlKeyAdox = new ADOX.Key();

sqlconAdo_Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbFile, "", "", -1);
sqlcatAdox.ActiveConnection = sqlconAdo;
sqltableAdox.Name = strTableName;
sqltableAdox.ParentCatalog = sqlcatAdox;

sqltableAdox.Columns.Append("ID", ADOX.DataTypeEnum.adInteger, 3);
sqltableAdox.Columns["ID"].Properties["Autoincrement"].Value = true;
sqltableAdox.Columns["ID"].Properties["Nullable"].Value = false;
sqltableAdox.Columns["ID"].Properties["Jet OLEDB:Allow Zero Length"].Value = false;

sqltableAdox.Columns.Append("DEPTID", ADOX.DataTypeEnum.adInteger, 3);
sqltableAdox.Columns["DEPTID"].Properties["Nullable"].Value = false;
sqltableAdox.Columns["DEPTID"].Properties["Jet OLEDB:Allow Zero Length"].Value = false;

sqltableAdox.Columns.Append("SUBSECTION", ADOX.DataTypeEnum.adVarWChar, 10);
sqltableAdox.Columns["SUBSECTION"].Properties["Nullable"].Value = false;
sqltableAdox.Columns["SUBSECTION"].Properties["Jet OLEDB:Allow Zero Length"].Value = false;

sqlcatAdox.Tables.Append(sqltableAdox);
 
ok bit of messing but... after this line (BTW changed the 3 to a 6)
Code:
sqltableAdox.Columns.Append( "ID", ADOX.DataTypeEnum.adInteger, 6 );
put this..
Code:
sqltableAdox.Keys.Append( "PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "ID", null, null );
hope this helps

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top