100分求!!高手请进来,渴求答案,动态建立ACCESS,并建立每个字段之属性!!
ADOX动态建立ACCESS,比如我可以建立一个自动增加的字段,但是怎么建立一个字段,并设置其为掩码,或者是check状态。这些状态 我们在ACCESS中,设计视图然后选择常规中的掩码属性可以更改,大家可以看到还有很多属性,请问高手动态建立时加什么样的语句可以实现此功能!
我用的是VB.NET ,谢谢大家了!!
[解决办法]
<%@ Page Language= "VB " %>
<%@ Import Namespace= "ADOX " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dbName As String = "D:\NewMDB " + DateTime.Now.Millisecond.ToString + ".mdb "
Dim cat As ADOX.CatalogClass = New ADOX.CatalogClass
cat.Create( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dbName + "; ")
Response.Write( "数据库: " + dbName + "已经创建成功! ")
Dim tbl As ADOX.TableClass = New ADOX.TableClass
tbl.ParentCatalog = cat
tbl.Name = "MyTable "
Dim col As ADOX.ColumnClass = New ADOX.ColumnClass
col.ParentCatalog = cat
col.Type = ADOX.DataTypeEnum.adInteger
col.Name = "id "
col.Properties( "Jet OLEDB:Allow Zero Length ").Value = False
col.Properties( "AutoIncrement ").Value = True
tbl.Columns.Append(col, ADOX.DataTypeEnum.adInteger, 0)
Dim col2 As ADOX.ColumnClass = New ADOX.ColumnClass
col2.ParentCatalog = cat
col2.Name = "Description "
col2.Properties( "Jet OLEDB:Allow Zero Length ").Value = False
tbl.Columns.Append(col2, ADOX.DataTypeEnum.adVarChar, 25)
Dim col3 As ADOX.ColumnClass = New ADOX.ColumnClass
col3.ParentCatalog = cat
col3.Name = "数字 "
col3.Type = DataTypeEnum.adDouble
col3.Properties( "Jet OLEDB:Allow Zero Length ").Value = False
tbl.Columns.Append(col3, ADOX.DataTypeEnum.adDouble, 666)
Dim col4 As ADOX.ColumnClass = New ADOX.ColumnClass
col4.ParentCatalog = cat
col4.Name = "Ole类型 "
col4.Type = DataTypeEnum.adLongVarBinary
tbl.Columns.Append(col4, ADOX.DataTypeEnum.adLongVarBinary, 0)
tbl.Keys.Append( "PrimaryKey ", ADOX.KeyTypeEnum.adKeyPrimary, "id ", " ", " ")
cat.Tables.Append(tbl)
msg.Text = ( " <br> 数据库表: " + tbl.Name + "已经创建成功! ")
System.Runtime.InteropServices.Marshal.ReleaseComObject(tbl)
System.Runtime.InteropServices.Marshal.ReleaseComObject(cat)
tbl = Nothing
cat = Nothing
GC.WaitForPendingFinalizers()
GC.Collect()
End Sub
</script>
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head id= "Head1 " runat= "server ">
<title> 在.NET框架下动态创建Access数据库和表 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:Label ID= "msg " runat= "server " />
</form>
</body>
</html>
[解决办法]
手动创建满足需求的表,在access的sql视图中获取ddl,在运行时组装类似的ddl运行即可
如Alter Table [tablename] Add [auto_increase_coloumn_name] int identity(1,1)