例子: Dim cat As New ADOX.Catalog Dim tbl As New ADOX.Table ' Open the catalog cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=.\\NorthWind.mdb;"' Create a new Table object. With tbl .Name = "Contacts" ' Create fields and append them to the new Table ' object. This must be done before appending the ' Table object to the Tables collection of the ' Catalog. .Columns.Append "ContactName", adVarWChar .Columns.Append "ContactTitle", adVarWChar .Columns.Append "Phone", adVarWChar .Columns.Append "Notes", adLongVarWChar .Columns("Notes").Attributes = adColNullable End With' Add the new table to the database. cat.Tables.Append tblSet cat = Nothing
允许 NULL 是允许将指针值设置为 0,它一般表示尚未赋值;而允许零长度是允许指针(不为零)所指向的缓冲区的数据长度可以为 0,也就是一个空字符串。当 Required 属性为 True,添加新记录时就必须为该字段赋值。可以赋一个空串,但不可以赋 NULL。实际上是允许改写指针所指缓冲区,不允许改写指针值。如果系统允许为字段赋值 NULL,字段的 Attributes 属性就必须包含 adFldIsNullable。并非所有的数据库都支持它,而且它在创建后就是只读的。
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=.\\NorthWind.mdb;"' Create a new Table object.
With tbl
.Name = "Contacts"
' Create fields and append them to the new Table
' object. This must be done before appending the
' Table object to the Tables collection of the
' Catalog.
.Columns.Append "ContactName", adVarWChar
.Columns.Append "ContactTitle", adVarWChar
.Columns.Append "Phone", adVarWChar
.Columns.Append "Notes", adLongVarWChar
.Columns("Notes").Attributes = adColNullable
End With' Add the new table to the database.
cat.Tables.Append tblSet cat = Nothing
col(i).Attributes = adColNullable
之后,就在
cat.tables.append tbl
时弹出“在项目中未找到的”错误
为什么?Attributes属性是否只对adLongVarWchar有效?
Attributes是否时应该在append tbl之后设置呢?