Solved

Quering a CRecordSet

Posted on 1998-11-09
7
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
csalves earned 200 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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