473,405 Members | 2,421 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,405 software developers and data experts.

SQL Breaks ASP

In one of our applications we have product id field which sometime contains
'

When doing a search the sql breaks due to this. I cannot use replace
function to remove this is there anything else I can do so that this works

strProductId = 2277'778

sqlstr = " Select * from productdetails where id ='" & strProductId & "'"

In this instance the sql breaks and gives me an error. Any suggestions how i
can solve this

Regards
Jul 19 '05 #1
5 1370
Hi JP,

The normal way would be to replace the single quote with 2 of them, but you
say you can't do that? Why?

Martin
"JP SIngh" <no**@none.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
In one of our applications we have product id field which sometime contains '

When doing a search the sql breaks due to this. I cannot use replace
function to remove this is there anything else I can do so that this works

strProductId = 2277'778

sqlstr = " Select * from productdetails where id ='" & strProductId & "'"

In this instance the sql breaks and gives me an error. Any suggestions how i can solve this

Regards

Jul 19 '05 #2
JP SIngh wrote:
In one of our applications we have product id field which sometime
contains '

When doing a search the sql breaks due to this. I cannot use replace
function to remove this is there anything else I can do so that this
works

strProductId = 2277'778

sqlstr = " Select * from productdetails where id ='" & strProductId &
"'"

In this instance the sql breaks and gives me an error. Any
suggestions how i can solve this

Regards


The easiest thing to do would be to use a saved parameter query if you are
using Access (look for posts by me containing those keywords), or a stored
procedure if you are using SQL Server.

Why can't you use Replace? It would look like this:

sqlstr = " Select * from productdetails where id ='" & _
Replace(strProductId,"'","''") & "'"

Bob Barrows
--
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 19 '05 #3
You are going to have to replace ' with ''. When sent to the database, this
will be seen as '.

The only other option is to create a stored procedure and send the string in
as a parameter.

If both options are impossible, you are stuck.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"JP SIngh" <no**@none.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
In one of our applications we have product id field which sometime contains '

When doing a search the sql breaks due to this. I cannot use replace
function to remove this is there anything else I can do so that this works

strProductId = 2277'778

sqlstr = " Select * from productdetails where id ='" & strProductId & "'"

In this instance the sql breaks and gives me an error. Any suggestions how i can solve this

Regards

Jul 19 '05 #4
"JP SIngh" <no**@none.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
In one of our applications we have product id field which sometime
contains '

When doing a search the sql breaks due to this.
Your solution is to double-up the single quotes as you build the SQL
string, as in

strProductId = "2277'778"
strProductId = Replace( strProductId, "'", "''" )
I cannot use replace function to remove this


You don't need to "remove" it, just make it safe to put into your SQL,
as above.

HTH,
Phill W.
Jul 19 '05 #5
thank you all

The replacement solution works fine
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:cf**********@yarrow.open.ac.uk...
"JP SIngh" <no**@none.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
In one of our applications we have product id field which sometime
contains '

When doing a search the sql breaks due to this.


Your solution is to double-up the single quotes as you build the SQL
string, as in

strProductId = "2277'778"
strProductId = Replace( strProductId, "'", "''" )
I cannot use replace function to remove this


You don't need to "remove" it, just make it safe to put into your SQL,
as above.

HTH,
Phill W.

Jul 19 '05 #6

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

Similar topics

1
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
1
by: ChrisC | last post by:
Im having trouble removing line breaks from my c# string. Actually, im having trouble getting .Trim() to work properly, as it seems to count a string that has nowt but a break of some sort as not...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
2
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
10
by: Evie | last post by:
I understand that when a switch statement is used without breaks, the code continues executing even after a matching case is found. Why, though, are subsequent cases not evaluated? I wrote a...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
2
by: caspardh | last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
8
by: Harris Kosmidis | last post by:
It seems I cannot understand CSS, well. I have donw the following page: http://www.pennias.gr/home.php It's in greek but the context is of no importance. I used a big table to put in my page...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
0
by: bblue | last post by:
hi, I need help in implementing page breaks in XML files? any suggestion on how can this be done? do you recommend using processing instructions or add a new elements would make more sense? can the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.