{
//为了方便测试,数据库名字采用比较随机的名字,以防止添加不成功时还需要重新启动IIS来删除数据库。
string time = DateTime.Now.Year.ToString()
if (DateTime.Now.Month <10)//判断当前月是否小于10
{
time += "0" + DateTime.Now.Month
}
else
{
time += DateTime.Now.Month
}
time += DateTime.Now.Day
string apppath = System.Web.HttpContext.Current.Request.ApplicationPath
string dbName = System.Web.HttpContext.Current.Server.MapPath("\\" + apppath + "\\NewMDB\\CGMDB" + time + ".mdb")
ADOX.CatalogClass cat = new ADOX.CatalogClass()
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0Data Source=" + dbName + "")
//ADODB.Connection cn = new ADODB.Connection()
//cn.Open("Provider=Microsoft.Jet.OLEDB.4.0Data Source=" + dbName + "", null, null, -1)
// cat.ActiveConnection = cn
ADOX.TableClass tbl = new ADOX.TableClass()
tbl.ParentCatalog = cat
tbl.Name = "WTMDBTable"
ADOX.ColumnClass col2 = new ADOX.ColumnClass()
col2.ParentCatalog = cat
col2.Name = "CheckSignNo"
col2.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col2, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col3 = new ADOX.ColumnClass()
col3.ParentCatalog = cat
col3.Name = "CarNo"
col3.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col3, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col4 = new ADOX.ColumnClass()
col4.ParentCatalog = cat
col4.Name = "CheckDate"
col4.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col4, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col5 = new ADOX.ColumnClass()
col5.ParentCatalog = cat
col5.Name = "TownClass"
col5.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col5, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col6 = new ADOX.ColumnClass()
col6.ParentCatalog = cat
col6.Name = "Address"
col6.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col6, ADOX.DataTypeEnum.adVarChar, 200)
//增加一个文本字段
ADOX.ColumnClass col7 = new ADOX.ColumnClass()
col7.ParentCatalog = cat
col7.Name = "Action"
col7.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col7, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col8 = new ADOX.ColumnClass()
col8.ParentCatalog = cat
col8.Name = "CarType"
col8.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col8, ADOX.DataTypeEnum.adVarChar, 50)
//增加一个文本字段
ADOX.ColumnClass col9 = new ADOX.ColumnClass()
col9.ParentCatalog = cat
col9.Name = "Mark"
col9.Properties["Jet OLEDB:Allow Zero Length"].Value = false
tbl.Columns.Append(col9, ADOX.DataTypeEnum.adVarChar, 50)
//设置主键
tbl.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "CheckSignNo", "", "")
cat.Tables.Append(tbl)
System.Runtime.InteropServices.Marshal.ReleaseComObject(tbl)
System.Runtime.InteropServices.Marshal.ReleaseComObject(cat)
tbl = null
cat = null
GC.WaitForPendingFinalizers()
GC.Collect()
}
以上代码可以完成创建一个MDB数据库了
好。ASP连接的数据库后缀名就是“mdb”,是一种数据库文件,asp使用mdb数据建站好。mdb格式是MicrosoftAccess软件使用的一种存储格式,因其对数据 *** 作的方便性,常用在一些中小型程序中。sql="create table mytable (m_id integer identity(1,1) primary key,m_class varchar(50) not null default 'AAA',m_int integer not null,m_numeric NUMERIC(6,2),m_money money not null default 0.00,m_memo text,m_date date default date(),m_boolean bit default yes,m_blob OLEObject,m_double double,m_float real)"'创建表
'm_id integer identity(1,1) primary key自动编号字段并制作主键
'm_class varchar(50) not null default 'AAA'文本型,长度50,非空,默认值:AAA
'm_int integer not null数字,长整型,非空
'm_numeric NUMERIC(6,2)数字,小数,精度6,数值范围2
'm_money money not null default 0.00货币,必添字段(非空),默认0
'm_memo text备注
'm_date date default date()日期/时间,默认当前日期(年月日)
'表中的各种数据类型基本都有了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)