错误子句中的语法错误,当我搜索名称时什么也没有显示

时间:2019-02-21 06:39:32

标签: vb.net

当我运行此代码时,它运行得很顺利,但是当我搜索名称时,没有记录出现。急需您的帮助人员来完成我们的计划项目。在此先感谢:)

这是我的代码:

Private Sub search_btn_Click(sender As Object, e As EventArgs) Handles search_btn.Click
    Me.Show()
    Search_Record()

End Sub

Private Sub Search_Record()
    Dim conn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim da As New OleDbDataAdapter
    Dim dt As New DataTable
    Dim sSQL As String = String.Empty

    Try

        conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\VB\HSU\HSU\G11B.mdb"

        conn.Open()
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        sSQL = "SELECT Last_Name, First_Name FROM 10ABM"
        sSQL = sSQL & "WHERE Last_Name like '%" & Me.search_txt.Text & "%'"
        cmd.CommandText = sSQL
        da.SelectCommand = cmd
        da.Fill(dt)
        Me.DataGridView1.DataSource = dt
        If dt.Rows.Count = 0 Then
            MsgBox("No record found!")
        End If
    Catch ex As Exception
        MsgBox(ErrorToString)
    Finally
        conn.Close()
    End Try

End Sub

0 个答案:

没有答案