472,353 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 7080
"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...
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...
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...
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...
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...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.