473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I create/set the PrimaryKey ?

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()+@"\BookC ollection.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.adVarWC har,20);

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

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

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

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

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

myTable.Name = "BookCollection";

// append the tables

myCatalog.Tables.Append(myTable);

return true;

}
Nov 16 '05 #1
2 3607
There's an example at
http://www.eggheadcafe.com/forums/Fo...15611&INTID=14

Chris Jobson

"Chris" <cl******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
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()+@"\BookC ollection.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.adVarWC har,20);

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

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

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

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

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

myTable.Name = "BookCollection";

// append the tables

myCatalog.Tables.Append(myTable);

return true;

}

Nov 16 '05 #2
Thanks Chris for the help. All is well and Merry Christmas! :D

-Chris

"Chris Jobson" <ch**********@btinternet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
There's an example at
http://www.eggheadcafe.com/forums/Fo...15611&INTID=14

Chris Jobson

"Chris" <cl******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
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()+@"\BookC ollection.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.adVarWC har,20);

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

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

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

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

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

myTable.Name = "BookCollection";

// append the tables

myCatalog.Tables.Append(myTable);

return true;

}


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Biswajit Barik | last post by:
Hi All, I want to create a cube using MSSQL2000 i dont know any thing how to create and what is parameter required so if any body help me i will be thankfull to him/her.For information : i have 4...
2
by: deko | last post by:
I'd like to use DDL (Data Definition Language) rather than VBA code to create a new table. The below DDL statement creates the table very nicely: CREATE TABLE tblTx03 (Subject Text (100),...
5
by: Sean Byrne | last post by:
We have a Microsoft Access 2000 database consisting of 20 tables covering 20 different events. In each table, there are 3 Team members, a date of the event and several unique fields for the event,...
1
by: sunlight_sg | last post by:
Hello, i am using ADOX + VB .NET to create a Access Database programmatically. I plan to set some properties of the column such primary key. The code is as follows: Dim cat As ADOX.Catalog...
4
by: Lars E | last post by:
Hi all How can i set primarykey to a datatable. This datatable is in a dataset i get from a backend system. My datatable contains several fields, and i want to make the fields "c-custno1",...
0
by: Indra Bisen | last post by:
Hi, I want to determine column names of Primary Key Columns of a SQL Server Table. To do this I've found following example in MSDN under PrimaryKey property of DataTable. I've add some lines of...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: Priya | last post by:
Hey all, Is there a way to create a table in the SQL database by using an XML file as an input? I want to have an XML file which holds all the details of the table like the tablename, columns,...
2
by: google | last post by:
How can I find a DataRow in a DataSet by it's PrimaryKey value? This would be similar to an SQL statement such as "SELECT * FROM MyTable WHERE MyIndex = 2"... In the following code I've tried to...
5
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. Basically what I would like to do is create a database that I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.