OK. Again...How to handle single quotes in SQL Strings?? ASP.NET/ADO.NET

S

SStory

How can I handle the user entering single quotes like in

Bob's mini mart?

If I use command objects will this no longer be an issue?

I guess that would mean no simple adhoc SQL statements right?

like SELECT name from WHATEVER

would need a command object with

"SELECT @NAME, etc.
and then params

is this the way to solve the problem?

Thanks,

Shane
 
C

Colin Young

Use command objects. The single quote "problem" will go away.

Don't use ad-hoc SQL statements that are concatenated from user input. You
are leaving your application vulnerable to a SQL injection attack.

Colin
 
S

SStory

OK. That is what I had thought.

So to do that in command ojbects I do something like.

dim cmd as new sqlCommand("SELECT Name,Address,City FROM tblPerson WHERE
State=@State",conn)

is that right? And then just add @State as a param?

I don't need to do the same for the output params right? LIke Name, Address
and City--or do I have to do them the same?

Shane
 
D

Dan Brussee

Basically correct.

Output parameters would need to be declared, but in your example, you
seem to be returning a recordset, not output parameters. This would
return a .NET dataset with multiple records which you could either
bind to an ASP control or use in whatever method you deem prudent :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top