Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 18th, 2004, 06:24 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Access database at runtime in C#

Look at the following code:

// catalog object
Catalog cat = new CatalogClass();
cat.Create(connStrAccess);

// naslov
Table dtNaslov = new TableClass();
dtNaslov.Name = "Naslov";
dtNaslov.Columns.Append("ID_Naslov",DataTypeEnum.a dInteger,4);
dtNaslov.Keys.Append("ID_Naslov",KeyTypeEnum.adKey Primary,"ID_Naslov","Naslov","ID_Naslov");
dtNaslov.Columns.Append("Ulica",DataTypeEnum.adVar WChar,50);
dtNaslov.Columns.Append("PostnaSt",DataTypeEnum.ad SmallInt,4);
dtNaslov.Columns.Append("Kraj",DataTypeEnum.adVarW Char,50);
cat.Tables.Append((object)dtNaslov);

// potnik
Table dtPotnik = new TableClass();
dtPotnik.Name = "Potnik";
dtPotnik.Columns.Append("ID_Potnik",DataTypeEnum.a dInteger,4);
dtPotnik.Keys.Append("ID_Potnik",KeyTypeEnum.adKey Primary,"ID_Potnik","Potnik","ID_Potnik");
dtPotnik.Columns.Append("ID_Naslov",DataTypeEnum.a dInteger,4);
dtPotnik.Keys.Append("ID_Naslov",KeyTypeEnum.adKey Foreign,"ID_Naslov","Naslov","ID_Naslov");
dtPotnik.Columns.Append("Ime",DataTypeEnum.adVarWC har,50);
dtPotnik.Columns.Append("Priimek",DataTypeEnum.adV arWChar,50);
cat.Tables.Append((object)dtPotnik);

// partner
Table dtPartner = new TableClass();
dtPartner.Name = "Partner";
dtPartner.Columns.Append("ID_Partner",DataTypeEnum .adInteger,4);
dtPartner.Keys.Append("ID_Partner",KeyTypeEnum.adK eyPrimary,"ID_Partner","Partner","ID_Partner");
dtPartner.Columns.Append("ID_Naslov",DataTypeEnum. adInteger,4);
dtPartner.Keys.Append("ID_Naslov",KeyTypeEnum.adKe yForeign,"ID_Naslov","Naslov","ID_Naslov");
dtPartner.Columns.Append("Naziv",DataTypeEnum.adVa rWChar,100);
cat.Tables.Append((object)dtPartner);


A problem is, when debug mode is trying to do cat.Tables.Append((object)dtPartner). It
throws an exception: "ID_Naslov object already exist". Why is that? I only want to
create a relationship between Naslov & Potnik tables and Naslov & Partner tables.
How can I create a Foreign key in table Partner? It generates Foreign key in table
Potnik perfectly, but in Partner table it throws an exception.
Can someone please help?

Oh, how can I add an AutoNumber field to the ID_Naslov? Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating login form with access database Belzebu Visual Basic 2005 Basics 0 November 8th, 2007 11:33 AM
Creating CheckBox at runtime. sachingowdar Java GUI 2 April 22nd, 2007 09:55 PM
Creating a DLL at runtime jai2k Beginning VB 6 1 January 5th, 2005 01:23 PM
Creating Access database at runtime janigorse Access 0 September 18th, 2004 03:48 AM
creating access runtime versions Loralee Access VBA 7 September 2nd, 2004 10:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.