Click here to Skip to main content
15,913,055 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Unit test cases for Web Services Pin
Luc Pattyn5-Oct-10 12:06
sitebuilderLuc Pattyn5-Oct-10 12:06 
GeneralRe: Unit test cases for Web Services Pin
Keith Barrow5-Oct-10 12:38
professionalKeith Barrow5-Oct-10 12:38 
QuestionShort key for proeject in Solution Explorer Pin
indian1435-Oct-10 5:27
indian1435-Oct-10 5:27 
QuestionNOOB Question: using LIKE in SelectParameter Pin
Figmo25-Oct-10 4:48
Figmo25-Oct-10 4:48 
AnswerRe: NOOB Question: using LIKE in SelectParameter Pin
Electron Shepherd5-Oct-10 5:06
Electron Shepherd5-Oct-10 5:06 
AnswerUse Parameterized queires Pin
David Mujica5-Oct-10 5:13
David Mujica5-Oct-10 5:13 
AnswerRe: NOOB Question: using LIKE in SelectParameter Pin
Keith Barrow5-Oct-10 5:13
professionalKeith Barrow5-Oct-10 5:13 
AnswerRe: NOOB Question: using LIKE in SelectParameter Pin
Figmo25-Oct-10 7:12
Figmo25-Oct-10 7:12 
Great suggestions all - thank you. What I ended up doing was a little different. I think elegant, but maybe not. Open to critiques...

I left the ControlParameter tied to my text box. (the parameter is called @SearchExpr)

My WHERE clause in the SelectCommand is simply "...WHERE Field LIKE @SearchExpr..." (no concatenation, thus no problems with single quotes needing to be escaped)

And added an event handler for SqlDataSource.Selecting that does this...

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)<br />
{<br />
    e.Command.Parameters["@SearchExpr"].Value = "%" + e.Command.Parameters["@SearchExpr"].Value + "%";<br />
}


So now the user just enters ANY search string into the text box (e.g. "O'Hara")
This is passed to the SelectCommand as a parameter, thus it is not executable code - so no worries about SQL injection (I think)
And then, in the event handler, right before the SelectCommand is applied to the SqlDataSource, I modify the value to add the % signs front and back.

It works like a charm but the only thing I am not certain of is how well protected I am against injection attacks. Am I right in assuming that this should be adequate protection?
GeneralRe: NOOB Question: using LIKE in SelectParameter Pin
Electron Shepherd5-Oct-10 8:11
Electron Shepherd5-Oct-10 8:11 
QuestionHow to present the link more elegant(ASP.Net,C#.Net) [modified] Pin
Jayadheer Reddy5-Oct-10 3:40
Jayadheer Reddy5-Oct-10 3:40 
AnswerRe: How to present the link more elegant(ASP.Net,C#.Net) Pin
Brij5-Oct-10 4:56
mentorBrij5-Oct-10 4:56 
QuestionGridview with rows calcul Pin
amina895-Oct-10 3:11
amina895-Oct-10 3:11 
AnswerRe: Gridview with rows calcul Pin
NeverHeardOfMe5-Oct-10 3:37
NeverHeardOfMe5-Oct-10 3:37 
AnswerRe: Gridview with rows calcul Pin
Brij5-Oct-10 4:06
mentorBrij5-Oct-10 4:06 
QuestionRe: Gridview with rows calcul Pin
amina895-Oct-10 23:41
amina895-Oct-10 23:41 
QuestionXML Problem Pin
InderK5-Oct-10 1:37
InderK5-Oct-10 1:37 
AnswerRe: XML Problem Pin
torken25-Oct-10 2:16
professionaltorken25-Oct-10 2:16 
AnswerCross post Pin
Not Active5-Oct-10 2:24
mentorNot Active5-Oct-10 2:24 
QuestionPrevent upload of renamed and Password protected file in asp.net C# Pin
Arokiamary5-Oct-10 1:27
Arokiamary5-Oct-10 1:27 
AnswerRe: Prevent upload of renamed and Password protected file in asp.net C# Pin
Not Active5-Oct-10 2:22
mentorNot Active5-Oct-10 2:22 
AnswerRe: Prevent upload of renamed and Password protected file in asp.net C# Pin
NeverHeardOfMe5-Oct-10 3:23
NeverHeardOfMe5-Oct-10 3:23 
Questionquery string question Pin
swjam4-Oct-10 23:28
swjam4-Oct-10 23:28 
AnswerRe: query string question Pin
Gamzun5-Oct-10 0:24
Gamzun5-Oct-10 0:24 
GeneralRe: query string question Pin
swjam5-Oct-10 0:59
swjam5-Oct-10 0:59 
GeneralRe: query string question Pin
Not Active5-Oct-10 1:18
mentorNot Active5-Oct-10 1:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.