2
Answers

How to change statment to accept (= and like) in same time

ahmed sa

ahmed sa

10y
698
1
Hi guys i make dynamic filter in datagridview but i face proplem
when i using to search for number as example
555 and inside id three values as 555,5555,55555 it give me three value
but actually there are one value found so that i need to use equal =  with like statment in same time
are this possible my code as below:
 



private void searchgrid_TextChanged(List<field> fields)

 System.Data.DataView dv = ((System.Data.DataView)dataGridView1.DataSource); //
 _textFilters = ""; //reset filters











bool first = true; //to handle the " and "








foreach (field f in fields)




{




if (f.Value.Length > 0) //only if there is a value to filter for




{




if (!first) _textFilters += " and ";




_textFilters += f.Field + " like '%" + f.Value + "%'";








 first = false;




}
}
dv.RowFilter = _textFilters;




this.label1.Text = _textFilters;




}




Answers (2)
0
Nir Bar
NA 773 0 15y
Hi Petre,

There isn't an automatic way of doing it.
I think the best way will be to count day-by-day in a loop:
int count = 0;
for( DateTime d = dt1.Value.Date; d <= dt2.Value.Date; d = d.AddDays(1))
{

if(( d.DayOfWeek != DayOfWeek.Saturday) && (d.DayOfWeek != DayOfWeek.Sunday))
{
++count
}
}
return count


Please mark this post as an answer if it helps you

Nir