M.Lopez
M.Lopez

Reputation: 67

SQL Server LIKE statement with multiple values?

Forgive if the question is repeated, I'm new to this site.

Been trying to create a search text box for a program that saved and organized documents. The software is database-based, and it can search for only one column at a time. I need it to look for any info in any column (expect date).

Here is the code:

private void textBox2_TextChanged(object sender, EventArgs e)
{
        DataView vista = new DataView(tablaSql);
        vista.RowFilter = string.Format("asunto_corres LIKE'%{0}%'", textBox2.Text);
        dgTodo.DataSource = vista;
}        

It works but only with the name of the column specified.

Any help to make this textbox look for info in any field/column.

Thanks

Upvotes: 0

Views: 1022

Answers (2)

Steve
Steve

Reputation: 5545

You can do it by adding some "OR" operators:

vista.RowFilter = string.Format("asunto_corres LIKE'%{0}%' OR Column2 LIKE'%{0}%' OR ...", textBox2.Text);

Upvotes: 0

mnieto
mnieto

Reputation: 3874

try:

vista.RowFilter = string.Format("{0} LIKE'%{1}%'", fieldName, textBox2.Text);

Upvotes: 2

Related Questions