“System.Runtime.InteropServices.COMException”类型的未经处理的异常

An unhandled exception of type 'System.Runtime.InteropServices.COMException'

提问人:Дима 提问时间:10/6/2023 最后编辑:Дима 更新时间:10/6/2023 访问量:74

问:

我需要有关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,更改了位置,但相同的错误仍然存在。

vb.net visual-studio ms-access com ado

评论

0赞 jmoerdyk 10/6/2023
Stack Overflow 主网站上的所有问题和答案都必须使用英文。请翻译您的问题或尝试 Stack Overflow на русском, 但一定要遵循他们的内容指南如何提问,以确保主题问题.
0赞 June7 10/6/2023
ID 是什么数据类型?如果是“自动编号”,则不要插入值。虽然 INSERT 应该可以工作,但不要这样做 - 让表生成下一个数字 - 这就是自动编号的本质。建议不要使用保留字作为名称:NAME 是保留字。更好的是 EmpName。此外,ID 可能最终出现在多个表中,重命名为唯一名称,例如 EmpID。
0赞 June7 10/6/2023
连接是否有效?您可以使用 SELECT 查询提取数据吗?
0赞 Дима 10/6/2023
真的,我什么也做不了,连连接都做不了。就像我航行一样:它在“猫”处破裂。ActiveConnection = connectionString”
0赞 June7 10/6/2023
查看 stackoverflow.com/questions/4234941/...。你的连接对我来说看起来不错。

答: 暂无答案