First off: *never* concatenate user input; use parameters instead...
i.e. "AND ProductID LIKE @ProductID"
(and add a parameter named @ProductID with Value =
productInfo1.ProductID + "%".
However; back to the question ;-p Various options:
* A checkbox next to each that checks itself automatically when a
value is entered, but can be checked manually for searching blank
* Radios for value / blank: (o) [Textbox] (o) (blank) - defaults to
value obviously (and selecting (blank) would disable the Textbox)
* Drop-down list of available options, with (blank) at the top?
* A more dynamic search UI - i.e. user adds criteria by selecting a
property (from a list) *and* the value - and can and multiple rows -
i.e.
[Name] = Fred
[Order Ref] =
[Foo] = bar
[Select option] = {value}
(the bottom option adds a new row; the Order Ref is searching for a
blank)
This approach also: handles large numbers of searchable fields without
needing a massive search form; allows for more complex "(this and
that) or (theother)" searches; makes it easier to fit operator options
(equals/starts-with/less-than/more-than etc) without making the UI too
ugly (OK; still ugly, but not too much so).
Of course, the alternative would be to go all "google", with a single
text-box and simply parse the tokens - i.e.:
Name=Fred and Order Ref = "" and Foo=bar
(or something)
Marc
> First off: *never* concatenate user input; use parameters instead...
> i.e. "AND ProductID LIKE @ProductID"
> (and add a parameter named @ProductID with Value =
> productInfo1.ProductID + "%".
thanks i missed that in this one. My other code does that but i looked
right over it here.
> However; back to the question ;-p Various options:
> * A checkbox next to each that checks itself automatically when a
[quoted text clipped - 25 lines]
>
> Marc
what data structure you use for holding the search criteria with this
idea? I guess i could create one...perhaps something like
class Criteria
{
public string columnname;
public string value;
public Operation operator;
}
Enum Operation
{
Equals
, GreaterThan
, LessThan
...
}
Marc Gravell - 03 Jan 2008 20:33 GMT
> perhaps something like
Depending on your actual requirements, yes; I have used something very
similar... probably not public fields, though ;-p
Marc
Marc Gravell - 03 Jan 2008 20:39 GMT
Actually - seeing the later posts, I'd agree that Expression is a
better way to encapsulate this...
Plus (as has already been pointed out) it would allow the system to
write the SQL for you.
For more info on building the query, see:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_t
hread/thread/76353240ec0652c3/4e2cc66c3d39ee9f
Marc