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 2 1003
I recall wroting some similar logic a year-or-so ago; re being generic
- anything that gets the mappings (sql columns to logical properties)
from some metadata store (for example, attributes or an xml file)
would be an option; as would support for more than just LIKE @foo +
'%', and the ability to perform multiple filters at once including
nesting of conditions "(x or y) and z".
Re technology; an obvious candidate here would be ORMs such as LINQ-to-
SQL. By creating a data-context, it is fairly trivial to write a
search screen:
IQueryable<Customerquery = ctx.Customers;
if(!string.IsNullOrEmpty(customerName)) query =
query.Where(x=>x.Name == customerName);
if(!string.IsNullOrEmpty(city)) query = query.Where(x=>x.City ==
city);
//...etc
List<CustomerresultsPage = query.Take(100).ToList();
which will give you the first 100 results where all the chosen options
matched. Note that much more complex queries are possible.
Marc
would anyone else like to expand with article examples, more insight, is
there a way to use interfaces in this case (with the exception of linq)?
"rodchar" wrote:
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Millie Niss |
last post by:
I am new to PHP and mySQL, and I am trying to build a database of
services (on a service table) provided by agencies (another table),
where one agency can provide many services, but a service...
|
by: rick.huby |
last post by:
This may not be the right place to post this - but if anyone can help
that would be great.
I want to add an Accessible search function to our website - the only
way I can do this is to find a...
|
by: francois |
last post by:
Hi everyone,
I'm new to webdesign and there are some things that I'm wondering.
Should I learn HTML hand crafting firt with CSS and then move to
Javascript or move to XHTML? Is HTML an essential...
|
by: ldufrane |
last post by:
Hi All,
I just started a project, which features various great websites that
use CSS/web standards, this projects also highlights what techniques
they use to create the wow effects, in certain...
|
by: ma740988 |
last post by:
I'm hoping my post here doesn't fall into the 'hard to say' category,
nonetheless I've been advised that multiple uses of accessor/mutator
(get/set) member functions can be viewed as a 'design...
|
by: Rolf Welskes |
last post by:
Hello,
for a large web site project we would like to use nested Master Pages.
Unfortunely VS2005 is not able to show pages in design mode when
nested Master pages are used.
This has the...
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the...
|
by: cj |
last post by:
Back some time ago I was playing with a little app in VB 2005 that used
a google web service to get search results. I was rebuilding this app
in 2008 today. I added the web service...
|
by: Andrey Hristoliubov |
last post by:
I am confident that I am one of the best c++ programmer in the world.
And now I am going to prove it to you.
My reference is Victor Bazarov,Valentin Samko, Alf P.Steinbach( Me and
Alf intern...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |