VB.net中的textchanged在我的gridview中不显示结果 [英] Textchanged in VB.net does not display results in my gridview

查看:227
本文介绍了VB.net中的textchanged在我的gridview中不显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这段代码,并且我在gridview中始终没有显示,首先它会加载,它显示我拥有的所有记录,但是当我使用textchange属性时,我始终没有获取我想要的列表

I am using this code and i always get no display in my gridview, at first it loads, it shows all the records i have,but when i use the textchange property i always dont get the list that i wanted

这是我的第一个加载数据的代码,它工作正常

Here is my first code for the load of data and it works fine

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

这是我编辑的第二个代码,使它简单

Here is my second code which i edited to make it simple

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

任何人都可以提出一个解决方案,我只是想在gridview中显示我数据库中的记录白我要在文本框中输入的文本的基础

Can anyone suggest a solution i just want to display the records in my database in the gridview whit a basis of text that i would input in the textbox

推荐答案

您可以尝试改变你的命令...在你的,你忘了&包括你的文本字段,所以你基本上忽略所有的东西,(选择*其中的名字像txtSearchBar1.Text)你不会返回任何东西,除非确实有一个名称匹配txtSearchBar1.Text作为记录。

Can you try changing your command to this... In yours, you forgot the "&" to include your textfield, so your basically ommitting everything as, (Select * where name like txtSearchBar1.Text) you wont return anything that is unless indeed theres a name matching "txtSearchBar1.Text" as a record.

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

这篇关于VB.net中的textchanged在我的gridview中不显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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