Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 10th, 2007, 02:31 PM
Authorized User
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default syntax for where clause with like operator

Using vb.net 2003 my command works as under
mySearchString = "Select * from tblEmployee" & " where Lastname = ' " & txtLastname.text & " '; "

but i want to use like operator instead of equals and it doesnt work with * (wildcard character)
mySearchString = "Select * from tblEmployee" & " where Lastname like ' " & txtLastname.text & " ' & * & ; "

I have tried to put * with various delimeters but none works. Greatly appreciate some help



Old June 10th, 2007, 07:04 PM
Authorized User
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho

I have finally solved the problem
Here is the solution

Select command shall look like this
"Select * from tblEmolyee " & " where lastname like '" & searchname & "%' "

I am just a beginner so the following statemnts shall be accepted with a grain of salt by other my kind of programmers.

I invite and would greatly appreciate if GURU'S make a statement so other poeple with my kind of limitations dont get a erroneous suggestion from me
The problem I was having with was placement of % (wild character) and spaces.
spaces in the statement text are accepted by VB.net as actual spaces in commandtext
therefore program was reading my statement as "SearchName(space)then %
or it was not finding a match


Old June 11th, 2007, 08:34 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

String concatenation the way you are doing it is not recommended (I'm not sure why more samples or instructional material don't provide the better way of doing it). Instead of chains of strings, use the String.Format() method. It makes for much more readable (and supposedly more efficient) string construction code. You can break it up any way you like depending on the complexity.

In your example:

mySearchString = "Select * from tblEmployee where Lastname like '{0}%';"
string.Format(mySearchString, txtLastname.text);

The {0} is a replacement token. First argument to Format() is the "formatting string" containing the token. The subsequent argument(s) are the replacement values corresponding to the indexed tokens ({0} {1} {2} ...). The method also supports formatting the values you pass in.

myString = string.Format("Tax: {0:C}", dblTax);

This will place the value from the double 'dblTax' into the string, formatting it as a currency.

Visit MSDN for more:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error (missing operator) ppenn Classic ASP Basics 3 November 5th, 2007 02:26 PM
Syntax error (missing operator) in query expressio annwilly Classic ASP Databases 1 June 7th, 2006 09:53 AM
Syntax Error /missing operator in Query Expression dsealer Classic ASP Databases 4 September 4th, 2004 07:19 PM
Syntax error (missing operator) in query expressio nidy_online Wrox Book Feedback 1 April 30th, 2004 06:40 PM
Syntax error (missing operator) in query expressio mvollmer Classic ASP Databases 7 December 5th, 2003 11:38 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.