Solved

Quering a CRecordSet

Posted on 1998-11-09
7
278 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Read about achieving the basic levels of HRIS security in the workplace.
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now