473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Apostrophe error while retrieving the record from the database

I am using a Replace function to replace single quotes with double when
submitting a text field in the database i.e. Replace (q, "'", "' ' ")
which works fine. When I retrieve the field from the database which has
apostrophe I am getting 'Object expected' error message. Is there a
way to fix this?
Thanks,
Bhavna

Jul 19 '06 #1
10 4100

Bhavna wrote:
I am using a Replace function to replace single quotes with double when
submitting a text field in the database i.e. Replace (q, "'", "' ' ")
which works fine. When I retrieve the field from the database which has
apostrophe I am getting 'Object expected' error message. Even though I am checking in the code for apostrophe. For e.g. strOutput = Replace(strOutput, "'", "'")
Is there a way to fix this?
Thanks,
Bhavna
Jul 19 '06 #2

Bhavna wrote:
I am using a Replace function to replace single quotes with double when
submitting a text field in the database i.e. Replace (q, "'", "' ' ")
which works fine. When I retrieve the field from the database which has
apostrophe I am getting 'Object expected' error message. Is there a
way to fix this?
Thanks,
Bhavna
When I am retrieving the records from the db I am checking for
apostrophe. For e.g. strOutput = Replace(strOutput, "'", "'").
Still I am getting Object expected error message

Jul 19 '06 #3
Have you tried using chr() instead?
strOutput = Replace(strOutput, chr(34), chr(39))
..
"Bhavna" <bh**********@hotmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
>
Bhavna wrote:
I am using a Replace function to replace single quotes with double when
submitting a text field in the database i.e. Replace (q, "'", "' ' ")
which works fine. When I retrieve the field from the database which has
apostrophe I am getting 'Object expected' error message. Is there a
way to fix this?
Thanks,
Bhavna

When I am retrieving the records from the db I am checking for
apostrophe. For e.g. strOutput = Replace(strOutput, "'", "&apos;").
Still I am getting Object expected error message

Jul 19 '06 #4
One thing I don't understand anytime I am replacing anything with
apostrophe it's throwing an error. Any help is appreciated.
Thanks,
Bhavna

Jul 20 '06 #5
Bhavna wrote:
I am using a Replace function to replace single quotes with double
when submitting a text field in the database i.e.
What database? Type and version please. Never ask a database-related
question without revealing this information up front. It is almost
always relevant.
Replace (q, "'", "'
' ") which works fine. When I retrieve the field from the database
which has apostrophe I am getting 'Object expected' error message. Is
there a way to fix this?

Write a small page (a repro page) that contains the bare minimum amount
of code that shows how to reproduce the problem and post it here. Also
post instructions on how to create any database objects that are needed
to run the reproduce the problem. We should be able to run your repro
page in our environment and see the problem occurring.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 20 '06 #6
Example

dim namex
namex="Mc'Donalds"
Select name from table where name='" & namex & "'"

the ' in Mc'Donalds terminates the value to Mc and
will generate an error because of the extra ' generated by & "'"

This way of doing recordset queries is open to SQL
injection, so do not use it, it is just an example

"Bhavna" <bh**********@hotmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
One thing I don't understand anytime I am replacing anything with
apostrophe it's throwing an error. Any help is appreciated.
Thanks,
Bhavna

Jul 20 '06 #7
What about showing us some code ?

Also not sure but my understanding is that you change this particular
character both when storing and retrieving values ? If yes this is IMO a bad
approach as the character is not correctly stored in the DB which could be
not really convenient.

Depending on your DB the real problem is that the quote such as in 'O'Hara'
is seen as if it were the end marker of the string. Replacing by a double
quote will fix the problem 'O''hara'?
This will store O'Hara in the DB, you have the correct char in the DB and
you don't have any change to do when retrieving the value.

Another option is to use parameters instead of building SQL queries as
text...

Don't know but it lloks like that this problem could actually hide a design
problem you may want to check....

--
Patrice

"Bhavna" <bh**********@hotmail.coma écrit dans le message de news:
11*********************@b28g2000cwb.googlegroups.c om...
One thing I don't understand anytime I am replacing anything with
apostrophe it's throwing an error. Any help is appreciated.
Thanks,
Bhavna

Jul 20 '06 #8
ple help me anyone

i am using ms access database

tqty is text fields

rsCount.open "Select Sum(TQty) as temp from tbl_style where IPomsID="&
cdbl(request("IPomsID")),con,2,3

when i am exeuting query it gives below error

Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
rsCount.open "Select Sum(TQty) as temp from tbl_style where IPomsID="&
cdbl(request("IPomsID")),con,2,3
Bhavna wrote:
I am using a Replace function to replace single quotes with double when
submitting a text field in the database i.e. Replace (q, "'", "' ' ")
which works fine. When I retrieve the field from the database which has
apostrophe I am getting 'Object expected' error message. Is there a
way to fix this?
Thanks,
Bhavna
Jul 21 '06 #9

v.********@gmail.com wrote:
ple help me anyone

i am using ms access database

tqty is text fields

rsCount.open "Select Sum(TQty) as temp from tbl_style where IPomsID="&
cdbl(request("IPomsID")),con,2,3

when i am exeuting query it gives below error

Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.

Please don't append your question to other threads unless they are
relevant to that thread. Start a new thread instead.

Change TQty to a numeric field. You can't add text fields up as if
they are numbers.

--
Mike Brind

Jul 21 '06 #10
v.********@gmail.com wrote:
ple help me anyone

i am using ms access database

tqty is text fields

rsCount.open "Select Sum(TQty) as temp from tbl_style where IPomsID="&
cdbl(request("IPomsID")),con,2,3
If tqty is text, you cannot apply the Sum aggregate function to a text
field. What are you expecting this query to return? From the name of the
variable, rsCount, perhaps you are trying to find out how many records exist
with the specified lPomsID? If so, you need to use the Count function
instead of the Sum function. If so, reply and let us know because you need
to be made aware of how Count works.

Nothing to do with your problem but, hopefully you've done some validation
before attempting to run this statement so you don't get an error if
request("IPomsID") does not contain a number. This validation should be done
in your server-side code, before you even open your connection object. Do
not depend on client-side validation. Always validate user inputs in your
server-side code.

Also, it is a very bad practice to not specify the collection from which you
wish to retrieve the "IPomsID" variable. Never use request("IPomsID").
Always be explicit:: either request.form("IPomsID") or
request.querystring("IPomsID").

Further points to consider:
Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures, or saved parameter queries
as
they are known in Access:

Access:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 21 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JJP | last post by:
hi, I am searching a SQL database from an ASP page. When the user enters criteria with an apostrophe in it, result set is empty when there should be records. For example, the SQL database...
3
by: Peter Choe | last post by:
i am trying to add a record of a name. the name has an apostrophe (O'Neil). i am doing this through a servlet and wrote the code to use PreparedStatement. when i do: .... PrepareStatement...
2
by: CSDunn | last post by:
Hello, I have a combo box designed to look up records in a subform based on the selection made in the combo box. The Record Source for the combo box is a SQL Server 2000 View. There is one bound...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
1
by: geodev | last post by:
I’m copying data across from an Access database to an MSDE database through the use of some vb.net code. Unfortunately the application crashes when it goes to copy across data, in particular...
0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
3
by: travellinman | last post by:
Hi, currently i'm using the code below to select a record in a form by using a drop down box. However, when there is an apostrophe ( ' ) in the value of the selected record i get an error code. So...
3
by: pitchblack408 | last post by:
Hello I am using excel as my database and when I do an insert there is an apostrophe that appears in the cell where a string was inserted. For example '(474)343-3433 It appears that the...
9
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows()...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.