|
-
Mar 6th, 2006, 06:39 PM
#1
Thread Starter
Addicted Member
[RESOLVED] sql query in vb HELP
If an sql query has ' then how to avoid is..I know v can use the replace function n i have tried but it still gives me an error...does anybody have any function that returns a string..that formats a query..thanx
Last edited by Hack; Mar 7th, 2006 at 09:10 AM.
Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
-
Mar 6th, 2006, 06:50 PM
#2
Re: sql query in vb HELP
so you've already tried the below?
VB Code:
sql = Replace$(sql, "'", "''")
-
Mar 6th, 2006, 06:56 PM
#3
Thread Starter
Addicted Member
Re: sql query in vb HELP
yes i have tried it but still error..
my query is
psql = "select PriceCode from InsuranceTypes where Name='" & value & "'"
and value =Railway & Transport Employees' Friendly Society He
if i put that an call the function it still find a problem
-
Mar 6th, 2006, 07:06 PM
#4
-
Mar 6th, 2006, 07:12 PM
#5
Thread Starter
Addicted Member
Re: sql query in vb HELP
the error is the i replaces " with '..if i format the value only then its fine
-
Mar 6th, 2006, 07:14 PM
#6
Re: sql query in vb HELP
so you just need:
VB Code:
psql = "select PriceCode from InsuranceTypes where Name='" & Replace$(value, "'", "''") & "'"
-
Mar 6th, 2006, 08:11 PM
#7
Thread Starter
Addicted Member
Re: sql query in vb HELP
This is not working either now..how can i solve this..its really a pain
-
Mar 6th, 2006, 08:15 PM
#8
Re: sql query in vb HELP
Place
after you contruct the query and check the output for errors before sending it to the database.
-
Mar 6th, 2006, 08:21 PM
#9
Thread Starter
Addicted Member
Re: sql query in vb HELP
thanx mate..i solved it but its a bit strange..why can't v replace all the string but instead v have to do it with the value parameter
-
Mar 6th, 2006, 08:35 PM
#10
Re: sql query in vb HELP
why can't v replace all the string but instead v have to do it with the value parameter
All the text has to be enclosed within single quotes ('text goes here'), e.g.:
VB Code:
psql = Replace("select PriceCode from InsuranceTypes where Name='" & value & "'", "'", "''")
outputs:
VB Code:
select PriceCode from InsuranceTypes where Name= '' Railway & Transport Employees '' Friendly Society He ''
and none of the text is actually between the single quotes - so it errors:
However, with:
VB Code:
psql = "select PriceCode from InsuranceTypes where Name='" & Replace$(value, "'", "''") & "'"
the output is:
VB Code:
select PriceCode from InsuranceTypes where Name= 'Railway & Transport Employees' 'Friendly Society He'
and all the text is enclosed in single quotes - and it is processed correctly.
(I've edited the output strings so the quote pairs are made more obvious, it's not the true output.)
Is that what you were asking?
-
Mar 6th, 2006, 10:10 PM
#11
Thread Starter
Addicted Member
Re: sql query in vb HELP
I have to try one of ur first options the way ur doing it..wat i was doing is that constructing a string and passing it to a function that formats it..i'll c it n if i have any problems..i'l ask u..thanx for ur help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|