CDaoRecordset::FindFirst!!!

Dear All,

I have used the funciton FindFirst in order to locate the first matching method in my database and then update it with some data input by the user.

But I found that if the orginial data contain ' in the orginial data,
then no matching method can be found!!! Also, the return value of this function will not be equal to zero. It will udpate the first record of my database.

eg.

BOOL Find m_RsList->FindFirst([Telephone Number]='107' AND [First Name]='Win's' AND [Last Name]='Poon');


In the field "First Name", the content is Win's ....

How can I solve this problem?

Thanks!!!!
hon67Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TryCommented:
What do you mean by, "But I found that if the orginial data contain ' in the orginial data, then no matching method can be found!!!"?
0
vachoohoCommented:
"Win's" instead of 'Win's'
If it will not help  try

[FirstName] LIKE "Win's%"

0
freshmeatCommented:
try to replace any ' to ''
it is easy to replace that ', right?
for example:
BOOL Find m_RsList->FindFirst([Telephone Number]='107' AND [First
                      Name]='Win''s' AND [Last Name]='Poon');

for SQL thinks ' is a beginning or end of a string
:)
hope it is helpful to u
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

hon67Author Commented:
For inputting a statement in the FindFirst function, I found that I can't use the character (") in the statement...

For exampel

m_RSList->FindFrist("[Telephone Number]='107' AND [First Name]='Win"s' AND [Last Name]='Poon');

After modifying this, the progam cannot be complied.

What can I do to solve my problem?
0
hon67Author Commented:
For inputting a statement in the FindFirst function, I found that I
can't use the character (") in the statement...

For example

m_RSList->FindFrist("[Telephone Number]='107' AND [First
Name]='Win"s' AND [Last Name]='Poon'");

After modifying this, the progam cannot be complied.

What can I do to solve my problem
0
abk102299Commented:
> For example

> m_RSList->FindFrist("[Telephone Number]='107' AND [First
Name]='Win"s' AND [Last Name]='Poon'");

Try the following:

m_RSList->FindFrist("[Telephone Number]='107' AND [First Name]=\"Win's\" AND [Last Name]='Poon'");
0
hon67Author Commented:
After try this:
m_RSList->FindFrist("[Telephone Number]='107' AND [First
Name]=\"Win's\" AND [Last Name]='Poon'");

The record can be updated succesfully....but if the data become like this W"in's

m_RSList->FindFrist("[Telephone Number]='107' AND [First
Name]=\"W"in's\" AND [Last Name]='Poon'");

No matching record can be found!!!

Thus how can I use the FindFirst Function to find the matching record when the data at one of the fields contain both the ' and " characters.....?

Thanks!!!


0
vachoohoCommented:
Are you sure you realy have record with

([Telephone Number]='107' AND [First Name]='Win's' AND [Last Name]='Poon')

1) Is [Telephone Number] the field name?
2) Is it contain just '107'? (maybe LIKE '107%')
3) Is it text field?
4) Is the record you searching contain ALL three fields mentioned EXACTLY?

-------------------------------
Thus how can I use the FindFirst Function to find the matching record when the data at one of the fields contain both the ' and " characters.....?
--------------------------------
Try to replace all 's with +CHR(39)+

or all "s with +CHR(34)+

0
vachoohoCommented:
TRY using LIKE "*107*" for tel number
LIKE "*Win's*"


([Telephone Number] LIKE "*107*" AND [First Name] LIKE "*Win's*" AND [Last Name] LIKE "*Poon*")

place \ before each " for query string.


Note that Access use * as wildcard for any sequence of characters while SQL server use %.


0
CindyCCommented:
You can do this:
CString chFName = "Win's";
BOOL Find m_RsList->FindFirst([Telephone Number]='107' AND [First Name]='+ chFName +' AND [Last Name]='Poon');
Hope this helps.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vachoohoCommented:
Try to replace all 's with +CHR(39)+

thus

....[First Name]='Win'+CHR(39)+'s' ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.