3

I have been following this site for basic Access database implementation in C#

http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html

I want to search more than one row. This code works for one row.

string searchFor = txtFurniture.Text;
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "'");

How do I add in additional rows to check? I have tried something like

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + "Style='" + searchFor + "'");

but this fails.

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
Greg Innes
  • 63
  • 3

3 Answers3

1

you need to add and condition

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor +
                                           "' and Style='" + searchFor + "'");

In addition you can check this answer might help you to understand easily : Datatable select with multiple conditions

Community
  • 1
  • 1
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
1

You mean an additional field to check.

Make a condition that looks like this:

Finish='something' and Style='something'

using:

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' and Style='" + searchFor + "'");
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

As referenced in the documentation for the DataTable.Select method, the documentation for the DataColumn.Expression property describes the syntax to be used with the filterExpression parameter. In your case, use And to create a compound expression with your two conditions:

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' And Style='" + searchFor2 + "'");

...or more readably...

string filterExpression = string.Format("Finish='{0}' And Style='{1}'", searchFor, searchFor2);
DataRow[] returnedRows = ds1.Tables["Furniture"].Select(filterExpression);
Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68