我正在尝试从VB.Net项目中修改MS Access数据库的字段和表属性。
到目前为止,我已成功完成以下工作: 1-检索架构 2-检索表格说明 3-修改表中的字段描述
我还没有找到修改数据库中表的描述的方法。我正在使用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"
答案 0 :(得分:1)
ADOX无法使用Access表的Description
属性。您将需要使用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