gpt4 book ai didi

ms-access - 使用 ADOX 在 Access 中添加列时如何设置所需的属性?

转载 作者:行者123 更新时间:2023-12-04 06:12:44 28 4
gpt4 key购买 nike

我有以下脚本将列添加到 Access 数据库中的表。我不知道如何将该列的“必需”属性设置为“否”,默认为是。这是我的脚本:

Option Compare Database

Function AddColumns()
'Purpose: Show how to add fields to a table, and delete them using ADOX.
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As New ADOX.Column

Set cnn = CreateObject("ADODB.Connection")

cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=\\network\drive\TestDB.accdb; Jet OLEDB:Database Password=testing; "

'Initialize
cat.ActiveConnection = cnn
Set tbl = cat.Tables("Test_Table")

'Add a new column
With col
.Name = "Test_Column"
.Type = adVarWChar 'Decimal type.
'.Precision = 28 '28 digits.
'.NumericScale = 8 '8 decimal places.

End With
tbl.Columns.Append col
MsgBox col.Name & " successfully added"
Set col = Nothing
'Debug.Print "Column added."


'Clean up
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing

End Function

最佳答案

您需要使用 Attributes Property (ADOX)

例如

With col
...
.Attributes = adColNullable
...
End With

关于ms-access - 使用 ADOX 在 Access 中添加列时如何设置所需的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585509/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com