How do I create/set the PrimaryKey ?

C

Chris

Hello,
The following code works fine, but I need to set the `ISBN` to be the
primary key. I'm using ADO, C# and haven't come across anything that google
could help me with.

Any pointers/tips/help would be appreciated....Thank you for your time....



public bool CreateDataBase()

{

Catalog myCatalog = new ADOX.CatalogClass();

ADOX.IndexClass myIndex = new ADOX.IndexClass();

string dbPath =
System.IO.Directory.GetCurrentDirectory()+@"\BookCollection.mdb";

// build the database

myCatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;"+"Data
Source="+dbPath+";"+"Jet OLEDB:Engine Type=5");

// build the tables

Table myTable = new TableClass();

myTable.Columns.Append("ISBN",DataTypeEnum.adVarWChar,20);

myTable.Columns["ISBN"].ParentCatalog=myCatalog;

myTable.Columns.Append("Title",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Author",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Publisher",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Cost",DataTypeEnum.adCurrency,10);

myTable.Name = "BookCollection";

// append the tables

myCatalog.Tables.Append(myTable);

return true;

}
 
C

Chris

Thanks Chris for the help. All is well and Merry Christmas! :D

-Chris

Chris Jobson said:
There's an example at
http://www.eggheadcafe.com/forums/ForumPost.asp?ID=15611&INTID=14

Chris Jobson

Chris said:
Hello,
The following code works fine, but I need to set the `ISBN` to be the
primary key. I'm using ADO, C# and haven't come across anything that
google could help me with.

Any pointers/tips/help would be appreciated....Thank you for your
time....



public bool CreateDataBase()

{

Catalog myCatalog = new ADOX.CatalogClass();

ADOX.IndexClass myIndex = new ADOX.IndexClass();

string dbPath =
System.IO.Directory.GetCurrentDirectory()+@"\BookCollection.mdb";

// build the database

myCatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;"+"Data
Source="+dbPath+";"+"Jet OLEDB:Engine Type=5");

// build the tables

Table myTable = new TableClass();

myTable.Columns.Append("ISBN",DataTypeEnum.adVarWChar,20);

myTable.Columns["ISBN"].ParentCatalog=myCatalog;

myTable.Columns.Append("Title",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Author",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Publisher",DataTypeEnum.adVarWChar,20);

myTable.Columns.Append("Cost",DataTypeEnum.adCurrency,10);

myTable.Name = "BookCollection";

// append the tables

myCatalog.Tables.Append(myTable);

return true;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top