office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access DAO與ADO創建索引時一些屬性的區彆及對應關繫

2002-06-16 17:48:00
tmtony-Office交流網
原創
4932
DAO與ADO創建索引時一些屬性的區彆及對應關繫
DAO:
Required = True
IgnoreNulls = True Or False
ADO:
adIndexNullsDisallow 空值是不允許的, 索引項沒有加上

DAO:
Required = False
IgnoreNulls = True
ADO:
adIndexNullsIgnore 索引字段允許空值, 但索引項不添加

DAO:
Required = False
IgnoreNulls = False
ADO:
adIndexNullsAllow 索引字段允許空值,添加索引項

zhuyiwen
好!

esmile
難得齣現有DAO與ADO有針對性比較的貼子,希望多多……

ADAM
這樣啊,我這裡也有,貼一個吧:

DAO
Sub DAOCreatePrimaryKey()

    Dim db      As DAO.Database
    Dim tbl     As DAO.TableDef
    Dim idx     As DAO.Index
    
    'Open the database
    Set db = DBEngine.OpenDatabase("C:\nwind.mdb")
    
    Set tbl = db.TableDefs("Contacts")
    
    ' Create the Primary Key and append table columns to it.
    Set idx = tbl.CreateIndex("PrimaryKey")
    idx.Primary = True
    idx.Fields.Append idx.CreateField("ContactId")
    
    ' Append the Index object to the Indexes collection of the TableDef.
    tbl.Indexes.Append idx

    db.Close

End Sub

ADOX
Sub ADOCreatePrimaryKey()

    Dim cat     As New ADOX.Catalog
    Dim tbl     As ADOX.Table
    Dim pk      As New ADOX.Key
    
    ' Open the catalog
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\nwind.mdb;"

    Set tbl = cat.Tables("Contacts")
        
    ' Create the Primary Key and append table columns to it.
    pk.Name = "PrimaryKey"
    pk.Type = adKeyPrimary
    pk.Columns.Append "ContactId"
    
    ' Append the Key object to the Keys collection of Table
    tbl.Keys.Append pk
    
    Set cat = Nothing
    
End Sub

分享