473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to create a MS Access File

I search in all the Disscussion but can not found.

How can I create a MS Access Database file using C# code with a given Table
Structure ?

For example, I want to create a Access Database File with 2 tables: Student
and Department, of course, using C# code, not using MS Access to create
manually.

In Department table, I will have 3 Columns: DepartmentID (primary key, auto
increement), DepartmentName (Unique) and DepartmentDescription.

In Student Table I will have 4 columns: StudentID (primary key,
auto-increement), StudentName, DepartmentID (foreign key), and
StudentBirthday (date type).

Is there anyone could help me ?
Nov 23 '05 #1
10 7329
"Minh" <Mi**@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
Is there anyone could help me ?


I believe that the only way you can do this is with ADOX via InterOp...
Nov 23 '05 #2
> How can I create a MS Access Database file using C# code with a given Table
Structure ?


After you have a ADO.NET connection to an MDB file you can use SQL
commands and a Command object to create the structure (CREATE TABLE,
etc). However, I found no way to create the MDB file itself otherwise
than creating an empty one in Access.

Launch Access, create new blank database (MDB file), save, exit. You can
then connect to this file from C#. I think you could also keep the empty
file and duplicate that when you need new databases.

-Lenard
Nov 23 '05 #3
Oh, I think that there is a way to create MS Access database file by using C#
code only. Because Last month I had use a trial program that create MS Access
Database file without MS Access Installed in my computer.

Is there any one can help me ?

"Lenard Gunda" wrote:
How can I create a MS Access Database file using C# code with a given Table
Structure ?


After you have a ADO.NET connection to an MDB file you can use SQL
commands and a Command object to create the structure (CREATE TABLE,
etc). However, I found no way to create the MDB file itself otherwise
than creating an empty one in Access.

Launch Access, create new blank database (MDB file), save, exit. You can
then connect to this file from C#. I think you could also keep the empty
file and duplicate that when you need new databases.

-Lenard

Nov 23 '05 #4
> Oh, I think that there is a way to create MS Access database file by using C#
code only. Because Last month I had use a trial program that create MS Access
Database file without MS Access Installed in my computer.

Is there any one can help me ?


What I have done when I needed this:
- create an empty MDB with Access (as suggested)
- add it to the project (as embedded resource)
- when I need a new MDB, write that embedded file to the filesystem
So the program did "create" a new mdb file, but without Access-specific
commands.

Hans Kesting
Nov 23 '05 #5
Thanks for interesting

But Everytime, if you want your program run correctly, you always must have
an empty MS Access Database file. What's wrong if these database file has
been deleted ? Your program can not run.

My program allows user to create new database everytime they want, and can
run stand-alone.

In the past, my friend had done by this way (using code only to create MS
Database Access file) by using ADOX.CatalogClass.Create() but now I can not
find that code and example to do this.

Thanks you for help me. Again, if you could help me, please help me.

"Hans Kesting" wrote:
Oh, I think that there is a way to create MS Access database file by using C#
code only. Because Last month I had use a trial program that create MS Access
Database file without MS Access Installed in my computer.

Is there any one can help me ?


What I have done when I needed this:
- create an empty MDB with Access (as suggested)
- add it to the project (as embedded resource)
- when I need a new MDB, write that embedded file to the filesystem
So the program did "create" a new mdb file, but without Access-specific
commands.

Hans Kesting

Nov 23 '05 #6
I think your solutions sounds OK. But Can you show me how to save Embedded
Resource to File System ?

Thanks in advanced

"Hans Kesting" wrote:
Oh, I think that there is a way to create MS Access database file by using C#
code only. Because Last month I had use a trial program that create MS Access
Database file without MS Access Installed in my computer.

Is there any one can help me ?


What I have done when I needed this:
- create an empty MDB with Access (as suggested)
- add it to the project (as embedded resource)
- when I need a new MDB, write that embedded file to the filesystem
So the program did "create" a new mdb file, but without Access-specific
commands.

Hans Kesting

Nov 23 '05 #7
> I think your solutions sounds OK. But Can you show me how to save Embedded
Resource to File System ?

Thanks in advanced

Here is my code:

public void CreateDatabase()
{
const int size = 32768;

// read embedded resource empty.mdb,
// write with new name to binary file
byte[] buffer = new byte[size];
Stream mdbStream =
this.GetType().Assembly.GetManifestResourceStream( "<namespace>.Empty.mdb");
// NOTE: replace <namespace>

using (FileStream fs = File.Open(_config.DatabaseFile,
FileMode.OpenOrCreate, FileAccess.Write))
{
while (true)
{
int read = mdbStream.Read (buffer, 0, buffer.Length);
if (read <= 0)
break;
fs.Write(buffer, 0, read);
}
}
mdbStream.Close();
}

"Hans Kesting" wrote:
Oh, I think that there is a way to create MS Access database file by using
C# code only. Because Last month I had use a trial program that create MS
Access Database file without MS Access Installed in my computer.

Is there any one can help me ?


What I have done when I needed this:
- create an empty MDB with Access (as suggested)
- add it to the project (as embedded resource)
- when I need a new MDB, write that embedded file to the filesystem
So the program did "create" a new mdb file, but without Access-specific
commands.

Hans Kesting

Nov 23 '05 #8
Oh, It works greate. Again, thank you very much.

"Hans Kesting" wrote:
I think your solutions sounds OK. But Can you show me how to save Embedded
Resource to File System ?

Thanks in advanced


Here is my code:

public void CreateDatabase()
{
const int size = 32768;

// read embedded resource empty.mdb,
// write with new name to binary file
byte[] buffer = new byte[size];
Stream mdbStream =
this.GetType().Assembly.GetManifestResourceStream( "<namespace>.Empty.mdb");
// NOTE: replace <namespace>

using (FileStream fs = File.Open(_config.DatabaseFile,
FileMode.OpenOrCreate, FileAccess.Write))
{
while (true)
{
int read = mdbStream.Read (buffer, 0, buffer.Length);
if (read <= 0)
break;
fs.Write(buffer, 0, read);
}
}
mdbStream.Close();
}

"Hans Kesting" wrote:
Oh, I think that there is a way to create MS Access database file by using
C# code only. Because Last month I had use a trial program that create MS
Access Database file without MS Access Installed in my computer.

Is there any one can help me ?
What I have done when I needed this:
- create an empty MDB with Access (as suggested)
- add it to the project (as embedded resource)
- when I need a new MDB, write that embedded file to the filesystem
So the program did "create" a new mdb file, but without Access-specific
commands.

Hans Kesting


Nov 23 '05 #9

Here's a link to creating your DB from nothing

http://groups.google.com/group/micro...f6d8ef62fd67b0

Hope this helps.

-tomas
On Wed, 23 Nov 2005 01:19:11 -0800, "Minh"
<Mi**@discussions.microsoft.com> wrote:
I search in all the Disscussion but can not found.

How can I create a MS Access Database file using C# code with a given Table
Structure ?

For example, I want to create a Access Database File with 2 tables: Student
and Department, of course, using C# code, not using MS Access to create
manually.

In Department table, I will have 3 Columns: DepartmentID (primary key, auto
increement), DepartmentName (Unique) and DepartmentDescription.

In Student Table I will have 4 columns: StudentID (primary key,
auto-increement), StudentName, DepartmentID (foreign key), and
StudentBirthday (date type).

Is there anyone could help me ?


Nov 23 '05 #10
Thank you.

That's all I need to ask.

I have to choose the best way by create DB automatically or using as
Embedded Resource.

Once again, Thank you very much

"Tomas Vera" wrote:

Here's a link to creating your DB from nothing

http://groups.google.com/group/micro...f6d8ef62fd67b0

Hope this helps.

-tomas
On Wed, 23 Nov 2005 01:19:11 -0800, "Minh"
<Mi**@discussions.microsoft.com> wrote:
I search in all the Disscussion but can not found.

How can I create a MS Access Database file using C# code with a given Table
Structure ?

For example, I want to create a Access Database File with 2 tables: Student
and Department, of course, using C# code, not using MS Access to create
manually.

In Department table, I will have 3 Columns: DepartmentID (primary key, auto
increement), DepartmentName (Unique) and DepartmentDescription.

In Student Table I will have 4 columns: StudentID (primary key,
auto-increement), StudentName, DepartmentID (foreign key), and
StudentBirthday (date type).

Is there anyone could help me ?


Nov 23 '05 #11

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

Similar topics

3
by: fripper | last post by:
When testing a VB .Net application on my system (with IIS installed) I get an error message when using the fileopen function and the file does not exist ... i.e. I want fileopen to create the file....
2
by: david | last post by:
I'm developing a Visual C++ database application which will be delivered to customers. Some customers install Access 97 on their computers, others install Acess 2000 or higher versions. In my...
9
by: Albretch | last post by:
.. I am trying to create a database in a MS Access DB via JDBC drivers. I have tried both sun.jdbc.odbc.JdbcOdbcDriver and ids.sql.IDSDriver From some reason both drivers Exceptions tell me...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
1
by: Andrew Chanter | last post by:
I am writing a little routine to perform the following operations from an Acces 97 mdb: 1. create a fixed width text file 2. create/establish a table type link to the text file in Access 3....
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
9
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database...
6
by: JonSteng | last post by:
..Net Visual Studio Professional 2003 Version 7.1.3088 ..Net Framework 1.1 SP1 Version 1.1.4322 IIS 5.1 Windows XP Professional SP2 Micron T3000 Laptop (1.5 GHz; 1GB RAM; 40GB HD with 17GB Free)...
6
by: clusardi2k | last post by:
Hello again, I have to go home and read up on Access. But, I have read else-where in this newsgroup that I can just save the password in the database under scrutiny. Wouldn't it be wasteful...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.