Solved

listbox to sql

Posted on 1997-04-07
1
198 Views
Last Modified: 2010-04-06
I have a listbox that may contain the name of Cities that I want later to construct a sql statement that will locate these cities within a table. What is the right statement to build the string that would be used in the sql statement
0
Comment
Question by:azal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
javiertb earned 50 total points
ID: 1335238
Query1.Close;
Query1.SQL.Add('Select * from Table');

iSelected:=listBox.SelCount;

if (iSelected>0) then
   Query1.SQL.Add(' where ');

icount:=0;

while (iSelected>0) do
begin
   if (listBox.Selected[icount]) then
   begin
      Query1.SQL.Add(' city= '+ listBox.Items[icount]);
     
      iSelected:=iSelected-1;
     
      if (iSelected>0) then
         Query1.SQL.Add(' and ');      
   end

   icount:=icount+1;
end;

Query1.ExecSQL;


If you've got any problem, let me know.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question