views:

38

answers:

1

I'm developing a search form. It has about 10 fields and a search button that retrieve records from a table and put them in a gridview. The user can fill some fields, all the fields or none, and then click Search. Only the fields with info has to be used to perform the search.

I use a query in a tableadapter of a dataset to make the search and return a Datatable.

The query is like this:

Select * from table 
where (field1=@param1 or @param1 is null)
and (field2=@param2 or @param2 is null)
and (field3 like '%' + @param3 + '%' or @param3 is null)
....

Actually it works, but it is this the right way to do it? Am i missing something? I don't know why, but it don't seems very elegant to me...

Thanks