这段代码包含了一个adovbs.inc文件,这是个非常有用的文件,它定义了ADO和ADOX中用到的所有数值型变量,你可以在代码中找到该文件,也可以去你自己电脑上:C:\Program Files\Common Files\System\ado下找到。如果需要在你的页面中间引用,需要复制到网站自己的目录下边。1<!--#include virtual="/Includes/adovbs.inc"--> 2<% 3 Dim DBName,phyPath 4 DBName= "DB.mdb" 5 phyPath=Server.Mapath(DBName) 6 DTName="Contacts"
数据库创建完了,接下来该表了,否则我们要一个没有表的数据库是毫无意义的。下边是创建表的代码:1Sub CreateAccessDB(DBToCreate) 2 Dim catNewDB ' As ADOX.Catalog 3 Set catNewDB = Server.CreateObject("ADOX.Catalog") 4 catNewDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 5 "Data Source=" & Server.Mapath(DBToCreate) & _ 6 ";Jet OLEDB:Engine Type=5;" 7 ' Engine Type=5 = Access 2000 Database 8 ' Engine Type=4 = Access 97 Database 9 Set catNewDB = Nothing 10 End Sub
然后,可以在需要的地方调用:1 Sub CreateAccessTB(DBToCreate) 2 Dim catDB ' As ADOX.Catalog 3 Set catDB = Server.CreateObject("ADOX.Catalog") 4 ' Open the catalog 5 catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 6 "Data Source=" & Server.Mapath(DBToCreate) 7 Dim tblNew ' As ADOX.Table 8 Set tblNew = Server.CreateObject("ADOX.Table") 9 tblNew.Name = TBName 10 ' First Create an Autonumber column, called ID. 11 ' This is just for demonstration purposes. 12 ' You could have done this below with all the other columns as well 13 Dim col ' As ADOX.Column 14 Set col = Server.CreateObject("ADOX.Column") 15 With col 16 ParentCatalog = catDB 17 .Type = adInteger 18 .Name = "ID" 19 .Properties("Autoincrement") = True 20 End With 21 ' Now add the rest of the columns 22 With tblNew 23 ' Create fields and append them to the 24 ' Columns collection of the new Table object. 25 With .Columns 26 .Append "NumberColumn", adInteger 27 .Append "FirstName", adVarWChar 28 .Append "LastName", adVarWChar 29 .Append "Phone", adVarWChar 30 .Append "Notes", adLongVarWChar 31 End With 32 33 Dim adColNullable ' Is not defined in adovbs.inc, 34 ' so you need to define it here. 35 ' The other option is adColFixed with a value of 1 36 adColNullable = 2 37 With .Columns("FirstName") 38 .Attributes = adColNullable 39 End With 40 End With 41 ' Add the new Table to the Tables collection of the database. 42 catDB.Tables.Append tblNew 43 Set col = Nothing 44 Set tblNew = Nothing 45 Set catDB = Nothing 46 End Sub
1' First call the Create Database method 2 CreateAccessDB DBName 3 4 ' Then add a table and columns to this database 5 CreateAccessTB DBName
联系客服