は.Item("Key").Properties("AutoIncrement") = True
列タイプを自動インクリメント番号に設定していません。読み取り専用と書かれていますが、マイクロソフトの公式 Web サイトにあります。これは、Microsoft ドキュメントの更新されていない古いバージョンにありましたhttps://docs.microsoft.com/en-us/previous-versions/office/developer/office2000/aa164917(v=office.10)
動作しないようですVisual Studio 2012 vb.net の場合、列「キー」をauto increment number
?として設定する方法
エラー
プロパティ「アイテム」は「読み取り専用」です
Imports ADOX
Imports ADOX.DataTypeEnum
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Dim DB1_file_name As String = "\DB3.mdb"
Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Dim catstring As String
catDB = New ADOX.Catalog
' Open the catalog.
'catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.UserAppDataPath & "\DB1.mdb"
catstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.UserAppDataPath & DB1_file_name
catDB.Create(catstring)
'catDB.ActiveConnection = catstring
tblNew = New ADOX.Table
' Create a new Table object.
With tblNew
.Name = "Contacts"
With .Columns
.Append("Key", adInteger)
.Item("Key").Properties("AutoIncrement") = True
.Append("FirstName", adVarWChar)
.Append("LastName", adVarWChar)
.Append("Phone", adVarWChar)
.Append("Notes", adLongVarWChar)
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append(tblNew)
catDB = Nothing
End Sub
PS: コードを更新しました - それでもエラーが発生します
この接続を使用してこの操作を実行することはできません。このコンテキストでは、閉じているか無効です。
Imports ADOX
Imports ADOX.DataTypeEnum
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Dim DB1_file_name As String = "\DB3.mdb"
Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Dim catstring As String
catDB = New ADOX.Catalog
' Open the catalog.
'catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.UserAppDataPath & "\DB1.mdb"
catstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.UserAppDataPath & DB1_file_name
catDB.Create(catstring)
'catDB.ActiveConnection = catstring
tblNew = New ADOX.Table
' Create a new Table object.
With tblNew
.Name = "Contacts"
.ParentCatalog = catDB
With .Columns
.Append("Key", adInteger)
.Item("Key").Properties("AutoIncrement").Value = True
.Append("FirstName", adVarWChar)
.Append("LastName", adVarWChar)
.Append("Phone", adVarWChar)
.Append("Notes", adLongVarWChar)
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append(tblNew)
catDB = Nothing
End Sub