vb.net通过一个文本框过滤DatagridView中的多个列

时间:2015-04-03 17:15:44

标签: vb.net datagridview filter

我对VBA的VB.Net仍然很陌生,并试图找出如何使用一个搜索框中的值来过滤整个DataGridView。我目前正在使用VB.Net和MySql。下面的代码是我过滤掉一列而不是整个DataGrid的过程。请帮助,我感觉如此接近,但到目前为止。

提前致谢!

 Private Sub load_table()
    MySqlConn = New MySqlConnection
    MySqlConn.ConnectionString =
        "server=localhost;userid=root;password=M4cJunk13;database=database"
    Dim SDA As New MySqlDataAdapter
    Dim bSource As New BindingSource

    Try
        MySqlConn.Open()
        Dim Query As String
        Query = "select eid,name,surname,age from database.edata"
        COMMAND = New MySqlCommand(Query, MySqlConn)
        SDA.SelectCommand = COMMAND
        SDA.Fill(dbDataSet)
        bSource.DataSource = dbDataSet
        DataGridView1.DataSource = bSource
        SDA.Update(dbDataSet)

        MySqlConn.Close()

    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        MySqlConn.Dispose()
    End Try

我越来越近了,我能够过滤列名和列姓,但是列eid和列年龄会出错。

错误:无法执行'喜欢' system.int32和系统字符串上的操作。

我假设因为我混合整数和字符串会引发错误。 所以我想我的问题是如何过滤字符串和int?

    Private Sub Search_txt_TextChanged(sender As Object, e As EventArgs) Handles Search_txt.TextChanged
    Dim DV As New DataView(dbDataSet)
    DV.RowFilter = String.Format("eid Like '%{0}%' or name Like '%{0}%' or surname Like '%{0}%' or age Like '%{0}%' ", Search_txt.Text)
    DataGridView1.DataSource = DV
End Sub

0 个答案:

没有答案