在.net中创建Access数据库

static void Main(string[] args)
        {
            //环境要求
            //安装 access 2003,
            //引用com组件:Microsoft ADO Ext. 2.8 for DDL and Security
            string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;Jet OLEDB:Engine Type=5;";
            ADOX.CatalogClass cat = new ADOX.CatalogClass();
            cat.Create(connstr);
            string sql = @"CREATE TABLE user (
                    Name VARCHAR(50)  ,
                    CtfTp VARCHAR(10) ,
                    CtfId VARCHAR(255) ,
                    Gender VARCHAR(10) ,
                    Address VARCHAR(255) ,
                    Birthday VARCHAR(50) ,
                    Zip VARCHAR(255))";
            using (var connection = new OleDbConnection(connstr))
            {
                connection.Open();
                using (OleDbCommand command = new OleDbCommand(sql, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }

 

posted @ 2013-10-19 09:47  花生!~~  阅读(341)  评论(0编辑  收藏  举报