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?
 
CindyCConnect With a Mentor Commented:
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
 
vachoohoCommented:
Try to replace all 's with +CHR(39)+

thus

....[First Name]='Win'+CHR(39)+'s' ...
0
All Courses

From novice to tech pro — start learning today.