473,409 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

sql search string

10
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?
Oct 13 '08 #1
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

Expand|Select|Wrap|Line Numbers
  1. SELECT Customer.Name, Customer.Age, Customer.Gender, Customer.Active
  2. FROM    Customer
  3.  
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


Expand|Select|Wrap|Line Numbers
  1. SELECT Customer.Name, Customer.Age, Customer.Gender, Customer.Active
  2. FROM    Customer
  3. WHERE  Customer.Name = @Customer.Name
  4.  
In the above case you should supply the parameter @Customer.Name from your code.

I hope this help you.
Oct 14 '08 #2
Curtis Rutland
3,256 Expert 2GB
rpicilli,
the / goes inside the code tag:
[/code]

I fixed it for you this time.
Oct 14 '08 #3
Barok
10
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


Expand|Select|Wrap|Line Numbers
  1.  
  2. bool extensionset = tBoxSxExtension.Text.Length > 0 ? true : false;
  3. bool sizeset = ...
  4.  
  5.  
  6. if(extensionset && sizeset)
  7.  //do a query with extension and size
  8. elseif(extensionset && dateset)
  9.  //do a query with extension and creation date
  10. else if(extensionset && dateset && referenceset)
  11.  //do a query with extension, creation date and reference number
  12. else if(dateset && customerset)
  13.  //do a query with creation date and customer name
  14. else if(dateset && referenceset && customerset)
  15.  .... up to 30 if's..
  16.  
  17.  
i need to get rid of all those if's^^
Oct 14 '08 #4
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     Ass, Author, Cat, Dtq, Dta, Doc, Fic, Loc, Obs, TF1, Tdc, Tip
  3. FROM         TF1
  4. WHERE     (Doc LIKE @Doc) AND 
  5.                  (Tip LIKE @Tip) AND 
  6.                  (Cat LIKE @Cat) AND 
  7.                  (Ass LIKE @Ass) AND 
  8.                  (Author LIKE @Author) AND 
  9.                  (Dtq LIKE @Dtq) AND 
  10.                  (Dta LIKE @Dta) AND 
  11.                  (Loc LIKE @Loc) AND 
  12.                  (Obs LIKE @Obs)
  13.  
  14.  
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.
Oct 15 '08 #5
Barok
10
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!
Oct 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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:...
4
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...
22
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...
32
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...
0
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...
1
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...
4
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...
0
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...
0
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,...
0
Debadatta Mishra
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.