none
make a search routin to find FirstName by key pression RRS feed

  • Question

  • I want to have a search method in my app. I made this, but doesn't work probably...

    Private Sub TextBox1_TextChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles TextBox1.TextChanged 
    SqlDataAdapter1.SelectCommand.CommandText = "select * from Employees  WHERE (FirstName LIKE N'%" + TextBox1.Text + "%'"       
    SqlDataAdapter1.Fill(myDataSet11, "Employees"
    DataGridView1.DataSource = myDataSet11.Tables(0) 
    End Sub 

    What is the problem ?
    Monday, January 12, 2009 7:13 AM

Answers

  • Create a Dataview and set the rowfilter of that dataview

    Dim dv = New DataView(myDataSet11.Tables(0))
    dv.RowFilter = "FirstName LIKE '%" & Textbox1.text & "%'"
    DataGridView1.DataSource = dv
    Ewald - Please remember to mark the replies as answers if they help.
    • Marked as answer by Afshin_Zavar Thursday, January 15, 2009 8:49 PM
    Monday, January 12, 2009 8:02 AM
  • If you assign empty string to RowFilter then it will reset filtering and you will see all the rows.
    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Afshin_Zavar Monday, February 16, 2009 1:41 PM
    Tuesday, February 10, 2009 11:12 AM
    Moderator

All replies

  • Create a Dataview and set the rowfilter of that dataview

    Dim dv = New DataView(myDataSet11.Tables(0))
    dv.RowFilter = "FirstName LIKE '%" & Textbox1.text & "%'"
    DataGridView1.DataSource = dv
    Ewald - Please remember to mark the replies as answers if they help.
    • Marked as answer by Afshin_Zavar Thursday, January 15, 2009 8:49 PM
    Monday, January 12, 2009 8:02 AM
  • How can cancel row filter when there is nothing in Textbox ?!

    Following procedure doesn't work !

    1    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 
    2 
    3        Dim dv As DataView = New DataView(myDataSet.Tables(0)) 
    4
            dv.RowFilter = "FirstName LIKE '%" + TextBox1.Text + "%'" 


     
    5        If String.IsNullOrEmpty(TextBox1.Text.Trim()) Then 
    6            DataGridView1.DataSource = myDataSet 
    7        Else 
    8

               DataGridView1.DataSource = dv 
    10        End If 
    11 
    12    End Sub 
    13 

    Saturday, February 7, 2009 9:25 PM
  • If you assign empty string to RowFilter then it will reset filtering and you will see all the rows.
    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Afshin_Zavar Monday, February 16, 2009 1:41 PM
    Tuesday, February 10, 2009 11:12 AM
    Moderator