Solved

Mysql where clause in visual c++

Posted on 2004-09-29
2
362 Views
Last Modified: 2012-05-05
Hi,
I have a program in visual c++ .net that connects to a remote Mysql server.
Everything works just fine, I only have a problem when I execute a Mysql query to retrive data:

if I use the following it works just fine

            format = _T("SELECT * FROM clienti WHERE Client_code LIKE '%s'");

            sql.Format(format,m_searchString);

if I try to use this:

            format = _T("SELECT * FROM clienti WHERE Client_code  LIKE '%s' || Name LIKE '%s'");

            sql.Format(format,m_searchString);

where I only added "OR" to wide the search, either gives no result at all or only gives results of the first where clause "Client_code  LIKE '%s' "

I wonder if I need a special syntax to implement "OR" and "AND" statement in visual c++ .net and libmySQL.

Do you have any ideas??

thanks rik

0
Comment
Question by:rcinformatica
2 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 500 total points
ID: 12178792
If you change || to OR, it should give you the proper results:
format = _T("SELECT * FROM clienti WHERE Client_code  LIKE '%s' OR Name LIKE '%s'");
Plus, there's a problem with your Format call. You're only giving it one variable to match one %s; you need a variable for each %s.
sql.Format(format,m_searchString, m_searchString);

Hope this helps.
0
 

Author Comment

by:rcinformatica
ID: 12179101
exactly what I needed thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now