Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Quering a CRecordSet

Posted on 1998-11-09
7
Medium Priority
?
321 Views
Last Modified: 2011-10-03
I ran a query on my database looking for a record with the name---- O'Neal this name returns an error cause the " ' " is part of the SQL syntax, my question is how can i get arround this cause my database has a lot of names like this for example De'Abrew and De'Barros etc.
here's my code
CString str = "O'Neal";
m_pSet->Close();
m_pSet->m_strFilter = "[NAME] = '" + str + "'";
m_pSet->Open();
thanks in advance
0
Comment
Question by:mwebster
  • 3
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
csalves earned 800 total points
ID: 1025941
Hi,

You have to solve your problem in input. If you're working in VB you can substitute your ' for another carachter like ´.

If you don't have any similar carachter in your keyboard try to use a special simbol from ascii table.

You can teste this in VB for eg. i keyPreview of form.
if keyascii = ' (Ascii code) Then
   change for another carc.
end if

bye,
0
 

Author Comment

by:mwebster
ID: 1025942
good point but i'm using Visual C++5 is there another way???
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1025943
hi mwebster,

try to double or to triple the char ' when detecting.

i.e. O''Neil or O'''Neil

the sql-parser of your database deletes one or two depending on the database-os you use

meikl
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1025944
hi mwebster,

i see you have accept the given answer. have you checked out my comment or is there no interest for any further discussion?

meikl
0
 

Author Comment

by:mwebster
ID: 1025945
i did checked out your comment but it wont be very elegant to use double quotes in a person's name this problem even pops up  when i'm searching for an address sorry about that but only csalves seem to be the best answer. i solved the problem using his solution like this
i created a new class called CTrapEdit and subclassed the edit ctrl in my dlgbox traping the '\'' character whenever it's pressed
afx_msg void CTrapEdit::OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)
{
      if(nChar == '\'')
      {
              //change it to another character
      }
      CEdit::OnChar(nChar,nRepCnt,nFlags);
}

BEGIN_MESSAGE_MAP(CTrapEdit,CEdit)
      ON_WM_CHAR()
END_MESSAGE_MAP()



and in my dlgBox OnInit function
i did this
m_edit.SubclassDlgItem(IDC_EDIT1,this);

and it worked hope this helps someone else outthere. of course if there's anyother way using visual C++ cuz i'm not very good a the SQL stuff feel free to lemme know
thanx again.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1025946
hi mwebster,

i don't mean to store or to display or to edit the name with double or triple quotes, only temporary to  build your filter-option. What do you do with stored names contains the char '. Do you convert them to ´ afterwise? I've checked it out with oracle and ' and ´ are different characters there.

Well, if you beginning with a empty table then your code is ok!

meikl
0
 

Author Comment

by:mwebster
ID: 1025947
yes this is with an empty table i haven't figured out yet how to do it with a table that has the names stored like this already
thanx again
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

783 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