hello
i wrote a little c# sql client and now i need to implement the search function. i need some ideas how to do this, next to hundreds of ifs, wich was my first way to implement it. i have 8 different textboxes to search for, any ideas?
5 1290
HI There.
There is a lot of way to do that. The easyest and fast way is to create Querys and call them from your code.
What type of db access are you using? Dataset, datatables, etc...
Again the best way is to create a Layer for data access into your application.
Into this layer you create the query and call from your code.
If you wanto to query your database table with multiples datas (your txtBox) you can use either way the "=" sign or "LIKE" command.
This is an exemple of quer agains a table named Customer -
SELECT Customer.Name, Customer.Age, Customer.Gender, Customer.Active
-
FROM Customer
-
This code will give you all the rows of the customer table.
If you want to filter the info get by the query, use something like that -
SELECT Customer.Name, Customer.Age, Customer.Gender, Customer.Active
-
FROM Customer
-
WHERE Customer.Name = @Customer.Name
-
In the above case you should supply the parameter @Customer.Name from your code.
I hope this help you.
rpicilli,
the / goes inside the code tag:
[/code]
I fixed it for you this time.
thanks rpicilli
this is the way ive done it, creating querys and call them from code.im working with dataset access.
what im looking for is a algorithm or some ideas to organize the querystring
scenario 1:
you know specific data about the file, the name, the size, date of creation.., do a normal query
scenario 2:
you know nothing about the file, check which boxes are selected and organize the querystring -
-
bool extensionset = tBoxSxExtension.Text.Length > 0 ? true : false;
-
bool sizeset = ...
-
-
-
if(extensionset && sizeset)
-
//do a query with extension and size
-
elseif(extensionset && dateset)
-
//do a query with extension and creation date
-
else if(extensionset && dateset && referenceset)
-
//do a query with extension, creation date and reference number
-
else if(dateset && customerset)
-
//do a query with creation date and customer name
-
else if(dateset && referenceset && customerset)
-
.... up to 30 if's..
-
-
i need to get rid of all those if's^^
Hi Barok,
May be I do not understood your question. Either way I'll tell what I've donne.
I have a situation where I've 9 textbox that are use to search a SQL table. I never know which one are filled or if all of them has data.
I don't want to test with IFs so I resolve my problem with the query that is showed below. You can create a query with LIKE statemenst empty. At least on SQL Server.
Let me know if this help you. -
-
SELECT Ass, Author, Cat, Dtq, Dta, Doc, Fic, Loc, Obs, TF1, Tdc, Tip
-
FROM TF1
-
WHERE (Doc LIKE @Doc) AND
-
(Tip LIKE @Tip) AND
-
(Cat LIKE @Cat) AND
-
(Ass LIKE @Ass) AND
-
(Author LIKE @Author) AND
-
(Dtq LIKE @Dtq) AND
-
(Dta LIKE @Dta) AND
-
(Loc LIKE @Loc) AND
-
(Obs LIKE @Obs)
-
-
In the query above, doesn't matter if one or more parameters has values. Of course as much as parameters you have, more accurated will be you results.
thank you very much rpicilli, this is exactly what im looking for.
i tried to filter out those values by code, instead of doing this by the querystring.
i do have sql-server 05 installed on my machine, but never learned enough of this powerfull db. maybe i should read more about it!!
so yes it does help me, thanks a lot!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anand Pillai |
last post by:
To search a word in a group of words, say a paragraph or a web page,
would a string search or a regexp search be faster?
The string search would of course be,
if str.find(substr) != -1:...
|
by: Ken Fine |
last post by:
I'm looking to find or create an ASP script that will take a string, examine
it for a search term, and if it finds the search term in the string, return
the highlighted search term along with the...
|
by: Phlip |
last post by:
C++ers:
Here's an open ended STL question. What's the smarmiest most templated way
to use <string>, <algorithms> etc. to turn this:
" able search baker search charlie "
into this:
" able...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: Hriday |
last post by:
Hi there,
I am working on a web application in ASP.NET
My web server and AD machine are in the same domain but
located on diffrent phisical machine, I am not able to
search user's info by the...
|
by: Eric |
last post by:
Hi: I have two files. I search pattern ":" from emails text file and
save email contents into a database. Another search pattern " field is blank. Please try again.",
vbExclamation + vbOKOnly...
|
by: BenCoo |
last post by:
Hello,
In a Binary Search Tree I get the error : Object must be of type String
if I run the form only with the "Dim bstLidnummer As New BinarySearchTree"
it works fine.
Thanks for any...
|
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: JamesOo |
last post by:
I have the code below, but I need to make it searchable in query table,
below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
|
by: Debadatta Mishra |
last post by:
Introduction
In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |