Mysql VB.net中的Textchanged不会在my gridview中显示结果

Mysql VB.net中的Textchanged不会在my gridview中显示结果,mysql,sql,vb.net,gridview,Mysql,Sql,Vb.net,Gridview,我正在使用这段代码,我的gridview中总是没有显示,起初它会加载,它会显示我所有的记录,但是当我使用textchange属性时,我总是得不到我想要的列表 这是我加载数据的第一个代码,它运行良好 Public Sub LoadDataPI() mycom.Connection = cn mycom.CommandText = <SQL>SELECT CDate as 'Date', AName as 'Applicant', DPosition as 'Positi

我正在使用这段代码,我的gridview中总是没有显示,起初它会加载,它会显示我所有的记录,但是当我使用textchange属性时,我总是得不到我想要的列表

这是我加载数据的第一个代码,它运行良好

Public Sub LoadDataPI()
    mycom.Connection = cn
    mycom.CommandText = <SQL>SELECT CDate as 'Date', AName as 'Applicant', DPosition as 'Position', Address, Gender, Telephone, Cellphone, Email, Bdate as 'Birthdate', CStatus as 'Civil Status', Height, Weight, Religion, Spouse FROM tbl_applicant </SQL>

    Dim myadap As New MySqlDataAdapter(mycom)
    Dim mydt As New DataTable

    myadap.Fill(mydt)
    grdApplicantsPI.DataSource = mydt
    myadap.Dispose()
End Sub
公共子加载数据pi()
mycom.Connection=cn
mycom.CommandText=选择CDate作为“日期”,AName作为“申请人”,DPosition作为“职位”,地址,性别,电话,手机,电子邮件,Bdate作为“出生日期”,CStatus作为“公民身份”,身高,体重,宗教信仰,tbl_申请人的配偶
Dim myadap作为新的MySqlDataAdapter(mycom)
将mydt设置为新数据表
迈达普填充量(mydt)
grdApplicantsPI.DataSource=mydt
myadap.Dispose()
端接头
这是我的第二个代码,我对它进行了编辑,使之变得简单

Private Sub txtSearchBar1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchBar1.TextChanged
    myr.Close()
    grdApplicantsPI.Refresh()
    mycom.Connection = cn
    mycom.CommandText = <SQL>SELECT CDate as 'Date',AName as 'Applicant Name' FROM tbl_applicant where AName LIKE '%"  txtSearchBar1.Text  "%'</SQL>

    Dim myadap As New MySqlDataAdapter(mycom)
    Dim mydt As New DataTable

    myadap.Fill(mydt)
    grdApplicantsPI.DataSource = mydt
    myadap.Dispose()
End Sub
Private Sub txtSearchBar1\u TextChanged(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理txtSearchBar1.TextChanged
myr.Close()
grdApplicantsPI.Refresh()
mycom.Connection=cn
mycom.CommandText=从tbl_申请人中选择CDate作为“日期”,选择AName作为“申请人名称”,其中AName类似“%”txtSearchBar1.Text“%”
Dim myadap作为新的MySqlDataAdapter(mycom)
将mydt设置为新数据表
迈达普填充量(mydt)
grdApplicantsPI.DataSource=mydt
myadap.Dispose()
端接头

有人能提出解决方案吗?我只想在gridview中显示数据库中的记录,并在文本框中输入文本。。。在您的示例中,您忘记了将“&”包含在文本字段中,因此您基本上将所有内容都匹配为,(选择*where name,如txtSearchBar1.Text),除非确实有一个名称匹配“txtSearchBar1.Text”作为记录,否则不会返回任何内容

 "SELECT CDate as 'Date',AName as 'Applicant Name' FROM tbl_applicant WHERE AName LIKE '%" & txtSearchBar1.Text & "%'"

请编辑该问题并添加所获得错误的详细信息。同样,在SQL的末尾,您没有对EmerContact字段应用任何条件。在指定
数据源之后,您不需要
grdApplicantsPI.Databind
吗?我不知道,我只是不知道如何在@np3s获得结果,所以请添加
grdApplicantsPI.Databind()
在第
grdApplicantsPI.DataSource=mydt
行之后,检查是否在网格中得到结果。当我输入代码
DataBind不是'System.Windows.Forms.DataGridView'的成员时,我会出现此错误。
@NP3