I want to search two string in datarows.For example;
string1="ex"
string2="ex2"
row1={'ex','ex2','ex3'....}---->True
row2={'ex3','ex1','ex2'....}---->True
row3={'ex2','ex5','ex6'....}---->False
Each line must have a value of two strings.. For This,
for (counter = 0; counter < array.Count; counter++)
{
int index=0;
ArrayList array3 = new ArrayList();
array3 = Split(array[counter].ToString());
foreach (DataRow row2 in data.Rows)
foreach (object obje in row2.ItemArray)
{
//Proceeds
}
}
}
I coding something.But I do not want to deal with pollution in the code... Is there an easy way to select method?
var result = data.AsEnumerable()
.Where(r => r.ItemArray.Contains(string1) || r.ItemArray.Contains(string2))
Try to do something like this:
first define a DataView
DataView dv = new DataView(dt)
where dt
is a DataTable
.
After apply RowFilter
dv.RowFilter = "CONTAINS(ColName, 'ex1') AND CONTAINS(ColName, 'ex2')"
.
Hope this helps.