|
-
Nov 26th, 2000, 11:25 PM
#1
Thread Starter
Lively Member
Code:
SQL = "select * from clients where clientID =" myvalue
how do i base my sql query to pull all the records out according to what the myvalue variable is???
any ideas??
thanks
-
Nov 26th, 2000, 11:31 PM
#2
Junior Member
It seems like you have the query built correcly, what
seems to be the problem?
-
Nov 27th, 2000, 01:37 AM
#3
How about trying
Originally posted by johnnyboy23
Code:
SQL = "select * from clients where clientID = " & myvalue
-
Nov 27th, 2000, 07:54 AM
#4
Junior Member
Make sure myvalue is a string.
If myvalue is numeric, use Str(myvalue)
-
Nov 28th, 2000, 06:50 AM
#5
Member
Use quotes if string
Be sure to use the quotes if you search for string. When I started programmin in VB3 (there was no Internet yet commonly spread) it took me 3 days to figure it out. Wish someone has told me that then:
Code:
SQL = "Select * FROM tblClients WHERE clientID = '" & str(myValue) & "'"
A mind is like a parachute, it has to open to let it work
www.2beesoft.com for Icon Manager with over 20.000 free icons
VB6 Ent. SP4, ASP, W2000/W98
-
Nov 28th, 2000, 08:00 PM
#6
Re: Use quotes if string
Originally posted by Berthil
Be sure to use the quotes if you search for string. When I started programmin in VB3 (there was no Internet yet commonly spread) it took me 3 days to figure it out. Wish someone has told me that then:
Code:
SQL = "Select * FROM tblClients WHERE clientID = '" & str(myValue) & "'"
Exactly right. Forgot about the quotes thing for strings, another one of the crazy things you have to do with vb, other languages don't require them.
-
Nov 29th, 2000, 07:47 AM
#7
Hyperactive Member
Hey Jethro
Hi Jethro,
About your comment:
"another one of the crazy things you have to do with vb, other languages don't require them"
Are you sure about this? I thought it's standard SQL to include the single quotes for strings, like Berthil explained.
I use them in Access and Oracle.
Not trying to sound like a smarty, just wondering.
Thanks,
JazzBass
JazzBass
In the .NET era
Trying to remember VB6
Progress: 
XP Professional @ Home
and @ the Office
-
Nov 29th, 2000, 04:11 PM
#8
Not a problem Jazz
We use both Pick and Universe, under these languages you can do something like.
Code:
txtName = "Kerry O'Brian"
select customer where name = txtname
name is of course a field in the file customer, and as such the relation is implied and doesn't have to be stated. Any variable can be thrown into a statement without need of quotation marks. Even better it doesn't matter if the variable is null...
-
Dec 6th, 2000, 05:28 PM
#9
Junior Member
I have a problem i want to pull data from Oracle.
This code works well.
sql_command = "select * from COMPANY where CO_NM1 = '" & c_name3 & "'"
But when c_name3 = "Arthurs's Books"
Then i am out of luck and get an error because of the single quote in Arthur's.
I have numerous ways around this problem but i do fin until i get to a variable with a single quote in it.
sql_command = "select * from COMPANY where CO_NM1 = """ & c_name3 & """"
Please help me.
Mark S
-
Dec 6th, 2000, 08:24 PM
#10
I think its to do with a single quote
Being a notation for a comment line in vb.
-
Dec 7th, 2000, 04:28 AM
#11
F@#$%&G single quotes!!
Single quotes are a curse to all VB database programmers! If there is one in your data, as Jethro said, the rest of the string is interpreted as a comment, not as SQL like you intended. Where I work we have a function that checks all text before it is put into a database so there are no hassles when it comes to retrieving the data. I think it was from a book(all due credit to its author!). This guarantees the data in your db is clean. If you really like single quotes in text try replacing them with ` before adding to the database(the function is called replace). You can see everything the function cleans out in the illegals string, I added a few charcters for the sake of the demo, you can alter this as you please.
usage
Code:
cleanstring(text1.text)
'then perform the insert of text1.text into database
Code:
Private Function cleanstring(str As String) As String
'clean illegal characters out of data
Dim i As Integer
Dim illegals As String
illegals = "~@^#&()`:;{}<>_?$'*%"""
For i = 1 To Len(illegals)
str = Replace(str, Mid(illegals, i, 1), " ")
Next i
cleanstring = str
End Function
-
Dec 7th, 2000, 06:28 AM
#12
Fanatic Member
In SQL Server, there is an option quoted identifier which allows the replacement of ' with '' in string literals. There must be an equivalent in Oracle. Have you tried ''?
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Dec 7th, 2000, 06:47 AM
#13
Hyperactive Member
Jethro
Thanks!
That sounds pretty cool. I don't mind the single quotes that much, since that's what I started with. Try asking me that 2 days ago when I was working on my own program trying to do a INSERT INTO state with about 8 variables. Then I would have been singing a different tune. 
Thanks again for the reply.
JazzBass
JazzBass
In the .NET era
Trying to remember VB6
Progress: 
XP Professional @ Home
and @ the Office
-
Dec 7th, 2000, 03:57 PM
#14
Madworm tried a similar thing
But our customers needed the single quote in names like O'Connor etc, couldn't train them into not using it....got the code from http://www.planetsourcecode.com to over-come this, but caren't quite find the actual source at the moment...must be in one of our dlls somewhere, though l would have thought our standards would have forced use of a function.
Will post up when l find it.
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
|