Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

ADOX multi-key primary key in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scooter - 26 Jul 2004 02:33 GMT
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
Herfried K. Wagner [MVP] - 26 Jul 2004 02:42 GMT
* publicscott@comcast.net (Scooter) scripsit:
> To add a composite (multiple column) primary key to an Access
> database using ADOX and C#:
[quoted text clipped - 13 lines]
> DataTypeEnum.adVarWChar, 250);
> catalog.Tables.Append(filesTable);

Your question doesn't seem to be related to .NET Windows Forms
programming, so I suggest to post it to the ADO.NET group:

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.