Board index » delphi » Listbox.items --> Sql

Listbox.items --> Sql

recently i asked a question and got the answer same day(thanks so much)
but there is an interesting problem.
i have a listbox1 , query1 ,button1  i add the strings in to the sql on
every button click here is my code.

query1.sql.add('Select Distinct Custname, Adress1, Adress2, City From
Customer');
query1.sql.add('where Custname In ('+listbox1.items.commatext+ ')');
this works. but if custname for example is John i get an error message while
execute the query , if custname is John Dowe  i dont get any error message
shortly : as i understand the strings should be 2 words  and there should be
a space between them for this code
what is the problem ?

Thank You

 

Re:Listbox.items --> Sql


Look at your SQL statement in the de{*word*81}. The CommaText property may not
wrap the string in quotes if there is only one word and SQL requires the
quotes.

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Listbox.items --> Sql


you are correct commatext doesnt wrap the string if it is1 word without any
space , i checked the result of the sql text before execute the query the
result is below

Select Distinct Custname,Adress1,Adress2, City From Customer
where chadi In ("Mike Taylor" , John , "John Wright")
Order By Custname, Adress1, Adress2, City
then i tried to add 1 more qoute but didnt work then add 2 qoutes ,3
qoutes..... but it didnt work
do you have an idea that how can i can add commatext to John ?

thank you so much

Quote

> Look at your SQL statement in the de{*word*81}. The CommaText property may not
> wrap the string in quotes if there is only one word and SQL requires the
> quotes.

> --
> Bill Todd (TeamB)
> (Questions received via email cannot be answered.)

Re:Listbox.items --> Sql


Write a routine that scans the string returned by the CommaText property.
Each time you find a comma make sure that the character before and after the
comma is a quote. If not, insert one.

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Listbox.items --> Sql


i tried many times but i cannot,i am going to be crazy,
 If you dont mind,could you show me with code please ?
Thank you so much

"Bill Todd (TeamB)" <b...@dbginc.com> wrote in message
news:8s57oi$fi57@bornews.borland.com...

Quote
> Write a routine that scans the string returned by the CommaText property.
> Each time you find a comma make sure that the character before and after
the
> comma is a quote. If not, insert one.

> --
> Bill Todd (TeamB)
> (Questions received via email cannot be answered.)

Other Threads