本文介绍了如何创建MS Access文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索所有的Disscussion但找不到。


如何使用给定表格的C#代码创建MS Access数据库文件

结构?


例如,我想创建一个包含2个表的Access数据库文件:学生

和部门,当然,使用C#代码,不使用MS Access手动创建



在Department表中,我将有3列:DepartmentID(主键,自动

increement),DepartmentName(Unique)和DepartmentDescription。


在学生表中我将有4列:StudentID(主键,

自动授予),StudentName ,DepartmentID(外键),和

StudentBirthday(日期类型)。


有没有人可以帮助我?

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 ?

推荐答案




我相信你能做到的唯一方法这是通过InterOp的ADOX ...



I believe that the only way you can do this is with ADOX via InterOp...





获得ADO.NET连接后对于MDB文件,您可以使用SQL

命令和Command对象来创建结构(CREATE TABLE,

等)。但是,我发现无法创建MDB文件本身,否则比在Access中创建一个空文件要好。


启动Access,创建新的空白数据库(MDB)文件),保存,退出。你可以

然后从C#连接到这个文件。我想你也可以保留空的

文件并在需要新数据库时复制它。


-Lenard



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




在与MDB文件建立ADO.NET连接后,可以使用SQL
命令和Command对象来创建结构(CREATE TABLE,
等)。但是,我发现无法创建MDB文件本身,否则比在Access中创建一个空文件。

启动Access,创建新的空白数据库(MDB文件),保存,退出。然后你可以从C#连接到这个文件。我想你也可以保留空的
文件,并在需要新数据库时复制它。

-Lenard



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



这篇关于如何创建MS Access文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:50