用ADO的数据库对象
Dim dbs As Database, tbl As TableDef, fld As Field
.....
Set fld = tbl.CreateField("订单ID", dbText)
这样可以创建文本形的字段,那么怎么创建自动编号啊?
如果不是用这种方法创建的,可以写出创建ACCESS数据库、表、以及字段的方法吗(字段的数据类型如:自动编号、整形、文本、日期等)?

解决方案 »

  1.   

    怎么创建自动编号啊?
    cn.Execute "ALTER TABLE testtable add COLUMN Id COUNTER (1, 1) "
      

  2.   

    '用ADOX建立数据库与表
    '引用Microsoft ADO Ext 2.5 for DDL and Security
    Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table
    Dim con As ADODB.Connection    On Error GoTo 0    ' Create the new database.
        Set cat = New ADOX.Catalog
        cat.Create _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & DatabaseName & ";"    ' Create a new table.
        Set tbl = New ADOX.Table
        tbl.Name = "TestTable"
        tbl.Columns.Append "FirstName", adVarWChar, 40
        tbl.Columns.Append "LastName", adVarWChar, 40
        tbl.Columns.Append "Birthdate", adDate
        tbl.Columns.Append "Weight", adInteger
        cat.Tables.Append tbl 
       
        '设置列可以为NULL    
        tb1.columns("Weight").Attributes=AdColNullable
       '或者tb1.Columns("Weight").Properties("Jet OLEDB:Allow Zero Length") = True

        ' Connect to the database.
        Set con = cat.ActiveConnection    ' Insert records.
        con.Execute "INSERT INTO TestTable VALUES ('Andy', 'Able', '1 Jan 1980', '150')"
        con.Execute "INSERT INTO TestTable VALUES ('Betty', 'Baker', #2/22/1990#, 70)"    ' Close the database connection.
        con.Close
        Set con = Nothing
        Set tbl = Nothing
        Set cat = Nothing
      

  3.   

    http://www.china-askpro.com/msg30/qa90.shtml
      

  4.   

    怎么实现自动生成自动编号呀?
    答:
    dim rs =select max(id) from tablename
    cmd.commandtext="create table tablename("& rs!(0)+1 &")"