Solved

Mysql where clause in visual c++

Posted on 2004-09-29
2
364 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 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