修改来自 .NET 的访问 table 的描述 属性
modify the Description property of an Access table from .NET
我正在尝试从 VB.Net 项目中修改 MS Access 数据库的字段和 table 属性。
到目前为止,我已经成功完成了以下操作:
1- 检索模式
2- 检索 Table 描述
3- 修改 table
中的字段说明
我还没有找到修改数据库中table描述的方法。我正在使用 ADODB 和 ADOX。
下面是我修改字段描述的方式:
Dim MyDB As New ADOX.Catalog
Dim MyTable As ADOX.Table
Dim DB As New ADODB.Connection
DB.Open("Provider='Microsoft.ACE.OLEDB.12.0';Data Source= 'People.accdb';")
MyDB.ActiveConnection = DB
MyTable = MyDB.Tables("People")
MyTable.Columns("MyID").Properties("Description").Value = "Changed"
访问 table 的 Description
属性 对 ADOX 不可用。你将需要使用 ACE DAO,像这样:
' required COM reference:
' Microsoft Office 14.0 Access Database Engine Object Library
'
' Imports Microsoft.Office.Interop.Access.Dao
'
Dim dbe As New DBEngine
Dim db As Database = dbe.OpenDatabase("C:\Users\Public\myDatabase.accdb")
Dim tbd As TableDef = db.TableDefs("Donors")
Dim newDescription As String = "This is the new table description."
Try
tbd.Properties("Description").Value = newDescription
Catch ex As Runtime.InteropServices.COMException
If ex.ErrorCode = -2146825018 Then
' Property not found.
tbd.Properties.Append(tbd.CreateProperty("Description", DataTypeEnum.dbText, newDescription))
Else
Throw
End If
End Try
我正在尝试从 VB.Net 项目中修改 MS Access 数据库的字段和 table 属性。
到目前为止,我已经成功完成了以下操作: 1- 检索模式 2- 检索 Table 描述 3- 修改 table
中的字段说明我还没有找到修改数据库中table描述的方法。我正在使用 ADODB 和 ADOX。
下面是我修改字段描述的方式:
Dim MyDB As New ADOX.Catalog
Dim MyTable As ADOX.Table
Dim DB As New ADODB.Connection
DB.Open("Provider='Microsoft.ACE.OLEDB.12.0';Data Source= 'People.accdb';")
MyDB.ActiveConnection = DB
MyTable = MyDB.Tables("People")
MyTable.Columns("MyID").Properties("Description").Value = "Changed"
访问 table 的 Description
属性 对 ADOX 不可用。你将需要使用 ACE DAO,像这样:
' required COM reference:
' Microsoft Office 14.0 Access Database Engine Object Library
'
' Imports Microsoft.Office.Interop.Access.Dao
'
Dim dbe As New DBEngine
Dim db As Database = dbe.OpenDatabase("C:\Users\Public\myDatabase.accdb")
Dim tbd As TableDef = db.TableDefs("Donors")
Dim newDescription As String = "This is the new table description."
Try
tbd.Properties("Description").Value = newDescription
Catch ex As Runtime.InteropServices.COMException
If ex.ErrorCode = -2146825018 Then
' Property not found.
tbd.Properties.Append(tbd.CreateProperty("Description", DataTypeEnum.dbText, newDescription))
Else
Throw
End If
End Try