Solved

Quering a CRecordSet

Posted on 1998-11-09
7
267 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query combine all charges 6 58
MYSQL Record Number 3 55
Android dev (database) question 2 60
MS Access question 11 50
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now