1

首先,我是 VB 新手,这是我第一个使用 OleDBConnection 的项目。

好的,所以我正在尝试使用 oleDbConnection 做最简单的事情(我假设)。我只想从 Access DB 中的表中读取数据,并将该信息显示到我的 winForm 中的保管箱(或任何东西)。

Public Class QueManger
Dim dbConnection As OleDbConnection
Dim dbCommand As OleDbCommand
Dim dbDataAdapter As OleDbDataAdapter
Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = \\atrts10\F:\Applications\ATRTaxCert\Development\mtaylor\TaxCert_be_test.accdb"
Dim dtMain As DataTable

Private Sub QueManger_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    StatusName()
End Sub

Private Sub StatusName()
    Dim taxconn As OleDbConnection
    Try

        taxconn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\atrts10\F:\Applications\ATRTaxCert\Development\mtaylor\TaxCert_be_test.accdb")
        Dim taxcmd As OleDbCommand = taxconn.CreateCommand
        taxcmd.CommandText = "SELECT StatusName FROM Status ORDER BY StatusName"
        Dim rdr2 As OleDbDataReader
        If taxconn.State = ConnectionState.Closed Then
            taxconn.Open()
        End If
        rdr2 = taxcmd.ExecuteReader

        'boxStatus.Items.Add("All")
        While rdr2.Read()
            boxClient.Items.Add(rdr2.Item("StatusName"))
        End While
    Catch ex As Exception

    Finally
        taxconn.Close()
    End Try
End Sub

当它尝试运行“taxconn.Open()”函数时出现错误。

错误提示“Microsoft Access 数据库引擎无法打开或写入文件 '\atrts10\F:\Applications\ARTtaxCert\Development\mtaylor\TaxCert_be_test.accdb'。它已被其他用户以独占方式打开,或者您需要权限才能查看和写入其数据。”

有什么想法吗?

4

1 回答 1

1

如果您正在编辑它们,请尝试首先在访问中关闭打开的表,并尝试在字符串之前添加“@”以使用您的路径。然后尝试使用这个连接字符串;

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + yourDataBasePath + ";Persist Security Info=False;";
于 2013-02-25T21:14:17.087 回答