473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

build sql query

How do I do this with parameterized query?
without parameterized query:
string search = "hello world search";

search = search.Replace(" ", " AND ");

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'
parameterized query:

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'

cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = search;

basically I am trying to perform a search where all the words in the
search string are present.

Howard

Nov 19 '05 #1
2 1462
Howard,

You specify parameters in a text query with a question mark.

So your sql would look like:

SqlCommand.CommandText = "SELECT * FROM TABLE1 WHERE TEXT LIKE '%'?'%'";
SqlCommand.CommandType = CommandType.Text;
SqlCommand.Parameters.Add("@search", SqlDbType.NVarChar).Value = search;
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Howard" <ho*******@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
How do I do this with parameterized query?
without parameterized query:
string search = "hello world search";

search = search.Replace(" ", " AND ");

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'
parameterized query:

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'

cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = search;

basically I am trying to perform a search where all the words in the
search string are present.

Howard

Nov 19 '05 #2
try an array and a loop:
string search = "hello world search";
cmd.CommandText= "select * from table1";
string sep = " where "
string[] terms = search.Split(' ');
for (int i =0; i < terms.length; ++i)
{
string pname = "@search" + i.ToString;
cmd.CommandText += sep + string.format("text like '%' + {0} +
'%'",pname);
cmd.Parameters.Add(pname, SqlDbType.NVarChar).Value = terms[i];
sep = " or ";
}
-- bruce (sqlwork.com);
"Howard" <ho*******@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
How do I do this with parameterized query?
without parameterized query:
string search = "hello world search";

search = search.Replace(" ", " AND ");

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'
parameterized query:

SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'

cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = search;

basically I am trying to perform a search where all the words in the
search string are present.

Howard

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2154
by: NotGiven | last post by:
I need to build a query based on what the user checks in the form. For example, if the user does not check certain fields, I don' tneed to use those in the query statement. Any ideas how to...
0
1398
by: newbie | last post by:
Hi all, I got a problem using the embedded python. I'll be appreciated if some one can show me the way. What i want is, 1.build a dll(test.dll/test.lib) which uses the embedded python, for...
1
2750
by: MichaelC | last post by:
Hi all, I'm a newbie to SQL and I need help with investigating what ways are possible to build an interface of some sort that wraps around a SQL query script. I have a simple SQL query which...
1
2751
by: Mark | last post by:
My Category and Product tables look like: TblCategory CategoryID Category TblProduct ProductID CategoryID Product
0
3484
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
4909
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
8
1626
by: Dave | last post by:
Hi all, I want to build a site which will allow me to restrict a users access based on assigned privileges and render pages with user-specific information. Some other features I would like to...
10
6840
by: VirtualLilac | last post by:
Hi, Am trying to build a database for non-profit organisation, its a volunteer job and nobody around to guide me. From my learning I could able to build few reports and forms but am feeling stuck...
3
7746
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window...
8
3144
by: Gari | last post by:
Hello, I am trying to build a filter query with some AND and OR. I have three text boxes and 5 check boxes. The checkboxes are linked via code to other textboxes for the purpose of the query. ...
0
7227
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
7127
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...
0
7331
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,...
1
7054
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...
0
7501
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
5633
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,...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.