Quote Originally Posted by cicatrix View Post
USE the example I showed you.
Never use string concatenation to build SQL statements if it can possibly be avoided. E.g.
vb.net Code:
  1. Dim query As String = "SELECT * FROM Table1 WHERE @Column1 = '' OR Column1 = @Column1 AND @Column2 = '' OR Column2 = @Column2"
  2. Dim command As New SqlCommand(query, connection)
  3.  
  4. command.Parameters.AddWithValue("@Column1", Me.TextBox1.Text.Trim())
  5. command.Parameters.AddWithValue("@Column2", Me.TextBox2.Text.Trim())
This is one option so that an empty TextBox will match every row. Alternatively you could write some conditional code that won't add the parameters at all for empty controls. No point handling the TextChanged events though. Just get all the values once when you execute the query.