C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help With SQL 'Like' Operator Posted by amanuel on 11 Dec 2007 at 3:51 AM
I am using Vb.net and MS Access database to search for a text similar entered by the user ,
Dim strSelectName As String = "SELECT * FROM tblNames WHERE [name] LIKE % " & txtExecuter.Text & " % "

but it seems I am using the wrong expression,any help plz.
Report
Re: Help With SQL 'Like' Operator Posted by Jonathan on 11 Dec 2007 at 2:23 PM
You need to single-quote the string you're trying to match...

Dim strSelectName As String = "SELECT * FROM tblNames WHERE [name] LIKE '%" & txtExecuter.Text & "%'"

You also need to call something on txtExecuter.Text to escape any special characters (like quotes) in it too, if this code is for real-world use and you're not already validating it in a way that excludes that. Otherwise you've got an SQL Injection security hole.

Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.