Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 10th, 2007, 02:31 PM
Authorized User
 
Join Date: Dec 2006
Location: Tucson, AZ, USA.
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


Yasho

yvk




yvk
__________________
yvk
Reply With Quote
  #2 (permalink)  
Old June 10th, 2007, 07:04 PM
Authorized User
 
Join Date: Dec 2006
Location: Tucson, AZ, USA.
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default

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

Yasho


yvk
Reply With Quote
  #3 (permalink)  
Old June 11th, 2007, 08:34 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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:
http://msdn2.microsoft.com/en-us/lib...ng.format.aspx

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.