VB.net System.Data.OleDb.OleDbException:'语法错误(缺少运算符)

时间:2018-02-21 13:04:43

标签: vb.net access oledbdataadapter

我在Visual Studio 2017中使用Access 2013作为数据库。数据库已连接,但除此之外我运行此代码:

myConnToAccess = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database11.accdb")
    myConnToAccess.Open()
    ds = New DataSet
    tables = ds.Tables
    da = New OleDbDataAdapter("SELECT Typ záznamu from Typ", myConnToAccess)
    da.Fill(ds, "Typ")
    Dim view1 As New DataView(tables(0))
    With ComboBox1
        .DataSource = ds.Tables("Typ")
        .DisplayMember = "Typ záznamu"
        .ValueMember = "Typ záznamu"
        .SelectedIndex = 0
        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
        .AutoCompleteSource = AutoCompleteSource.ListItems
    End With

我在查询表达式'Typzáznamu'中得到了** System.Data.OleDb.OleDbException:'语法错误(缺少运算符)。' **

我有

Dim mySQLCommand As OleDbCommand
Dim mySQLStrg As String
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim tables As DataTableCollection
Dim myConnToAccess As OleDbConnection
在课程开始时......还有:

Imports System.Data.OleDb

我不知道该怎么做...有人可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

如果您要查询列Typ záznamu,则需要将其放在方括号中,因为这两个词之间有space

da = New OleDbDataAdapter("SELECT [Typ záznamu] from Typ", myConnToAccess)

答案 1 :(得分:0)

我让它成功了:

这一行:

da = New OleDbDataAdapter("SELECT Typ záznamu from Typ", myConnToAccess)

需要看起来像这样:

 da = New OleDbDataAdapter("SELECT [Typ záznamu] from Typ", myConnToAccess)

唯一的区别在于列名。它需要处于严格的状态,或者你如何称之为 []