473,791 Members | 2,947 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.NVarC har).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 1478
Howard,

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

So your sql would look like:

SqlCommand.Comm andText = "SELECT * FROM TABLE1 WHERE TEXT LIKE '%'?'%'";
SqlCommand.Comm andType = CommandType.Tex t;
SqlCommand.Para meters.Add("@se arch", SqlDbType.NVarC har).Value = search;
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Howard" <ho*******@yaho o.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.NVarC har).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.NVarC har).Value = terms[i];
sep = " or ";
}
-- bruce (sqlwork.com);
"Howard" <ho*******@yaho o.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.NVarC har).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
2173
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 build this? Thanks.
0
1416
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 example, i want to use the 're' module. 2.build a exe(usedll.exe) which uses that dll. 3.use py2exe to eliminate the dependence of the python environment.
1
2779
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 we normally run inside Query Analyzer to update certain fields in the SQL DB based on FQDN provide by the user. The user normally opens up the query, edit the script to replay the xxxxx in the line "set @FQDN="xxxxx" with the node name and then
1
2787
by: Mark | last post by:
My Category and Product tables look like: TblCategory CategoryID Category TblProduct ProductID CategoryID Product
0
3517
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 boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
6
4940
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 ObjectKey="xxxxx"> .. .. .. <EventEnrollment InstanceNumber = "676">
8
1644
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 have are... i. to log failed access attempts. ii. to make information(text) on certain pages easily editable by a 1 group of 'non-technical' users.
10
6863
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 at one point. I have two tables tblWorkers and tblLocations (locations & volunteer positions & start and end time using lookup wiz.) and made relationship using tblJunction. I need to build a form which shows volunteers details and a sub-form...
3
7773
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 appears. It doesn't happen every time, and using the Zoom window works fine. It appears that it only happens when I want to modify an existing expression. This continues to happen even after the database is repaired and reopened. Anyone have any...
8
3170
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. The first three text boxes are:
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2913
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.