Link to home
Start Free TrialLog in
Avatar of hon67
hon67

asked on

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!!!!
Avatar of Try
Try

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!!!"?
"Win's" instead of 'Win's'
If it will not help  try

[FirstName] LIKE "Win's%"

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
Avatar of hon67

ASKER

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?
Avatar of hon67

ASKER

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
> 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'");
Avatar of hon67

ASKER

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!!!


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)+

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 %.


ASKER CERTIFIED SOLUTION
Avatar of CindyC
CindyC

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try to replace all 's with +CHR(39)+

thus

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