提问人:Дима 提问时间:10/6/2023 最后编辑:Дима 更新时间:10/6/2023 访问量:74
“System.Runtime.InteropServices.COMException”类型的未经处理的异常
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
问:
我需要有关COM对象的帮助,我是新手。我在 VB.NET 写作。 我在 cat 线上遇到错误。ActiveConnection = connectionString:
"System.Runtime.InteropServices.COMException: 'Arguments have an invalid type, go beyond the allowable range, or conflict with each other.'"
`Imports System.Collections.ObjectModel
Imports System.Data.OleDb
Imports ADOX
Imports ADODB
Imports System.Data.Common
Module Module1
Public Sub Main()
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\access\base.accdb;"
' Create an ADOX.Catalog object to work with the database
Dim cat As New Catalog()
cat.ActiveConnection = connectionString
' Create a new table
Dim table As New Table()
table.Name = "Employees"
' Create fields for the table
Dim idField As New ADOX.Column()
idField.Name = "ID"
idField.Type = ADOX.DataTypeEnum.adInteger
idField.ParentCatalog = cat
table.Columns.Append(idField)
Dim nameField As New ADOX.Column()
nameField.Name = "Name"
nameField.Type = ADOX.DataTypeEnum.adVarWChar
nameField.ParentCatalog = cat
table.Columns.Append(nameField)
' Add the table to the database
cat.Tables.Append(table)
' Open a connection to the database
Dim connection As New Connection()
connection.Open(connectionString)
' Add data to the table
Dim command As New Command()
command.ActiveConnection = connection
command.CommandText = "INSERT INTO Employees (ID, Name) VALUES (1, 'John')"
command.Execute()
' Close the connection
connection.Close()
End Sub
End Module
`
在Visual Studio中,我添加了引用:Microsoft ActiveX 6.0,Microsoft ADO 6.0。Microsoft Access 似乎是 2021 年版本。.NET Framework 是 4.8,我还安装了 AccessDatabaseEngine_X64 和 msoledbsql。
我在谷歌上搜索了所有东西,但似乎没有任何帮助(
我尝试将路径编写为 C:/access/base.accdb,更改了位置,但相同的错误仍然存在。
答: 暂无答案
评论