C#创建Access数据库和数据表

1. 创建Access数据库

ADOX.Catalog catalog = new ADOX.Catalog();
//创建Library数据库
catalog.Create("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = .\\Data\\Student.accdb;Jet OLEDB:Database Password = 123456");
//释放Catalog对Student.accdb的占用
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog.ActiveConnection);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog);

2. 创建数据表

string OleDbConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = .\\Data\\Student.accdb;Jet OLEDB:Database Password = 123456";
OleDbConnection cnn = new OleDbConnection(OleDbConnectionString);
cnn.Open();
OleDbCommand cmd = new OleDbCommand("create table Info (id char(15) primary key, name char(50))", cnn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cnn.Close();
cnn.Dispose();

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页