vb.net “OleDbException 未处理...... From 子句中的语法错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13543722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:17:31  来源:igfitidea点击:

"OleDbException was unhandled...Syntax error in From clause"

vb.netms-access

提问by Anshu arora

I am getting this error saying

我收到这个错误说

OleDbException was unhandled...Syntax error in From clause

OleDbException 未处理... From 子句中的语法错误

My code for login is given below.

我的登录代码如下。

Imports System.Data.OleDb

Public Class Login

Dim con As New OleDbConnection
Dim dt As New DataTable
Dim ds As New DataSet

Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Project work\anshu\fitness_0.1\Fitness.accdb"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
    Me.Close()

End Sub

Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click


    If check() = True Then
        Main.Show()
        Me.Hide()
    Else
        MsgBox("Enter vailid Username and Password", MsgBoxStyle.Information, "Login Validation Information")
    End If



End Sub

Public Function check()
    ds.Tables.Add(dt)
    con.Open()
    Dim da As New OleDbDataAdapter("select * from User", con)
    da.Fill(dt) ---->here is the error!

    For Each DataRow In dt.Rows
        If txtname.Text = DataRow(1) And txtpass.Text = DataRow(2) Then
            con.Close()
            Return True

        End If
    Next
    con.Close()
    Return False

End Function

End Class

回答by Fionnuala

User is a reserved wordand must be bracketed:

User 是一个保留字,必须用括号括起来:

"select * from [User]"