Here's a perplexing thought... right now I'm writing an application
that uses a web form, with many different input types. Some of these
types are lists that allow for multiple selections. After selecting
all the necessary values I want to run a SELECT statement on an SQL
database, but using 'parameters' to avoid injection attacks, etc...
So ideally I could run a command something like this:
SELECT * FROM mydatabase WHERE (field1 LIKE @field1, field2 LIKE
@field2, field3 =@someListValue 1 OR field3 = @someListValue2 , field4
LIKE @field4)
The reason I want to use parameters is that some of the values (eg.
field1) could be a text box field and could (possibly) result in
command such as:
SELECT * FROM mydatabase WHERE (field1 LIKE 'sometext';DROP TABLE....'
etc...
The values from text boxes aren't that much of a concern, because it's
a single entry and they can be easily parameterized. The problem is
with list boxes. Sure, I can iterate through the list, find out how
many items are selected in the list, create snippets of search strings
based on the number of items selected in that list and then put it all
together in the end to make a final query to present to the SQL server
using C#... but there has to be a nicer way. Especially with 40
different lists, drop-lists, radio buttons, and text boxes... this is
getting to be ugly looking code.
I'm just wondering if anyone else has experienced this and found a
better way.
hmmm... still pondering this as I write.
Thx. 1 1266
Check this out: http://codebetter.com/blogs/karlsegu...08/144263.aspx
I used the new XML Data Type in SQL Server 2005..you could also use the
CLR...and as some people pointed out, in 2000 you could use OpenXML...make
sure to read the comments for good input from people..
Karl
-- http://www.openmymind.net/ http://www.fuelindustries.com/
"Wayne Deleer" <wa***@digitalm eister.comwrote in message
news:11******** ************@j4 4g2000cwa.googl egroups.com...
Here's a perplexing thought... right now I'm writing an application
that uses a web form, with many different input types. Some of these
types are lists that allow for multiple selections. After selecting
all the necessary values I want to run a SELECT statement on an SQL
database, but using 'parameters' to avoid injection attacks, etc...
So ideally I could run a command something like this:
SELECT * FROM mydatabase WHERE (field1 LIKE @field1, field2 LIKE
@field2, field3 =@someListValue 1 OR field3 = @someListValue2 , field4
LIKE @field4)
The reason I want to use parameters is that some of the values (eg.
field1) could be a text box field and could (possibly) result in
command such as:
SELECT * FROM mydatabase WHERE (field1 LIKE 'sometext';DROP TABLE....'
etc...
The values from text boxes aren't that much of a concern, because it's
a single entry and they can be easily parameterized. The problem is
with list boxes. Sure, I can iterate through the list, find out how
many items are selected in the list, create snippets of search strings
based on the number of items selected in that list and then put it all
together in the end to make a final query to present to the SQL server
using C#... but there has to be a nicer way. Especially with 40
different lists, drop-lists, radio buttons, and text boxes... this is
getting to be ugly looking code.
I'm just wondering if anyone else has experienced this and found a
better way.
hmmm... still pondering this as I write.
Thx. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: serge |
last post by:
Using "SELECT * " is a bad practice even
when using a VIEW instead of a table?
I have some stored procedures that are
identical with the difference of one statement
in the WHERE clause. If I create a single View
and specify also in this View the WHERE clause
that is common in these stored procedures, I
will have the new stored procecures...
|
by: deko |
last post by:
Can the DROP TABLE statement be used with a select or where statement?
DROP TABLE SELECT *
FROM tblTablesImported
WHERE Import_ID Not In
(SELECT FROM tblTablesInternal);
Or do I have to supply a parameter like:
DROP TABLE Sheet1
|
by: Lars Netzel |
last post by:
This code works:
SELECT * INTO #Temp From tbl_employee
SELECT * FROM #Temp
Drop TABLE #temp
This does not:
SELECT * INTO #Temp From (Select * FROM tbl_employee WHERE EMP_ID = @id
UNION Select * FROM tbl_employee2 EMP_ID = @id)
SELECT * FROM #Temp
Drop TABLE #temp
|
by: serena.delossantos |
last post by:
Trying to insert into a history table. Some columns will come from
parameters sent to the store procedure. Other columns will be filled
with a separate select statement. I've tried storing the select return
in a cursor, tried setting the values for each field with a separate
select. Think I've just got the syntax wrong. Here's one of my...
|
by: SLIMSHIM |
last post by:
Hi,
I"m new to c# and .net. I wrote a small program to add rows to an access
table.
the program goes thru the motions but the data never gets there.
here is my code. I am intentionaly not using the form controls. I"m trying
to do it solely thru code. You can safely assume I have an access datsabase
with one table called who with three...
| |
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...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |