使用OleDBConnection读取表 [英] Reading tables using OleDBConnection

查看:213
本文介绍了使用OleDBConnection读取表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

First off, i'm new to VB and this is my first project using OleDBConnection.

好的,所以我正在尝试使用oleDbConnection(我认为)最简单的方法.我只想从Access DB中的表中读取数据,并将该信息显示在winForm中的保管箱(或其他任何内容)中.

ok, so i'm trying to the most simple thing using oleDbConnection (i assume). I just want to read data from a table in the Access DB and display that information to dropboxes (or anything) in my 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()"函数时出现错误.

The error comes when it tries to run the "taxconn.Open()" function.

错误显示"Microsoft Access数据库引擎无法打开或写入文件'\ atrts10 \ F:\ Applications \ ATRTaxCert \ Development \ mtaylor \ TaxCert_be_test.accdb'.它已经由另一个用户专门打开,或者您需要查看和写入其数据的权限."

The error says "The Microsoft Access database engine cannot open or write to the file '\atrts10\F:\Applications\ATRTaxCert\Development\mtaylor\TaxCert_be_test.accdb'. It is already opened exclusively by another user, or you need permission to view and write its data."

有什么想法吗?

推荐答案

如果正在编辑打开的表,请尝试首先在访问中关闭已打开的表,并尝试在字符串之前添加"@"以使用路径. 然后尝试使用此连接字符串;

try to close the opened table first in access if you are editing them, and try to add "@" before the string to use your path. then try to use this connection string;

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + yourDataBasePath + ";Persist Security Info=False;";

这篇关于使用OleDBConnection读取表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆