Developing a search screen [C# windows application]
hi,
i have a two panels on a winorm one is "FIND CRITERIA" and the second is "FOUND DATA", what i want to do is to write a simple sql that can take argument , because their are 8 different search criterias that a user can enter in order to refine a search.
1. date
2. number
3. account
now the user can enter the all three or either one of the above as soon as the input parameterz increase the search should be refined .
thanks in advance
any help
naura paxPosted Oct 29, 2009, 7:42 AM
now as i posted earlier you will end up with a string
whereClause which will have conditions for only those controls that you want them ( dates will come all the time and comboboxes will be considered only when anything is selected in them).
now you just have to append this string to your select query:
"Select a,b,c... from t1 join... " + whereClause.ToString();
simple isn't it?
naura paxPosted Oct 30, 2009, 4:55 AM
faraz akramPosted Oct 29, 2009, 7:46 AM
faraz akramPosted Oct 29, 2009, 7:37 AM
naura paxPosted Oct 29, 2009, 6:46 AM
you can write a dynamic sql query where you declare a string or StringBuilder object and append clause into it depending upon selected criteria either on a button click event (if you have search button) or on the Enter event of the control which is to be filled eg:
StringBuilder whereclause=new StringBuilder();
if(cmbAccountName.SElectedIndex>-1)
{
if (whereClause.Length==0) whereClause.Append(" Where "); else whereClause.Append(" And")";
whereClause.Append(" AccountID=" + cmbAccountName.SelectedValue);
}
and so on ... for all criteria. Then pass this string variable in your stored procedure where you excute query by exec() or sp_executesql.