R
rodchar
hi all,
i have a search control for Northwind Employees so they can search on just
about anything regarding Northwind Customers. The search control dynamically
builds the sql statement in the data layer based on employee search criteria
and sends it off as a parameterized query to sql server.
Here's a quick example of how it works:
StringBuilder sb = new StringBuilder();
sb.Append("SELECT * FROM Customers" + Environment.NewLine);
if (searchControlFilter == "ByCity")
{ sb.Append("WHERE City Like @city + "%"); }
if (searchControlFilter == "ByCountry")
{ sb.Append("WHERE Country Like @country + "%"); }
So, when users come up with another search idea we just add to the logic. So
the code, if you can imagine, can get complex.
This product is stable and has been in production for several years so this
logic is pretty baked in. I'm mainly asking for low impact improvements for
better code manageability (It'd be nice too if the search could be more
generic as well). But I also would like to hear, in general, other ways this
could have been done (newer technologies like linq).
This a MS Visual Studio 2005 ASP.Net(C#) product with a MS SQL Server 2005
backend. We are utilitizing AJAX and JQuery.
thanks,
rodchar
i have a search control for Northwind Employees so they can search on just
about anything regarding Northwind Customers. The search control dynamically
builds the sql statement in the data layer based on employee search criteria
and sends it off as a parameterized query to sql server.
Here's a quick example of how it works:
StringBuilder sb = new StringBuilder();
sb.Append("SELECT * FROM Customers" + Environment.NewLine);
if (searchControlFilter == "ByCity")
{ sb.Append("WHERE City Like @city + "%"); }
if (searchControlFilter == "ByCountry")
{ sb.Append("WHERE Country Like @country + "%"); }
So, when users come up with another search idea we just add to the logic. So
the code, if you can imagine, can get complex.
This product is stable and has been in production for several years so this
logic is pretty baked in. I'm mainly asking for low impact improvements for
better code manageability (It'd be nice too if the search could be more
generic as well). But I also would like to hear, in general, other ways this
could have been done (newer technologies like linq).
This a MS Visual Studio 2005 ASP.Net(C#) product with a MS SQL Server 2005
backend. We are utilitizing AJAX and JQuery.
thanks,
rodchar