Solved

listbox to sql

Posted on 1997-04-07
1
175 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
1 Comment
 
LVL 2

Accepted Solution

by:
javiertb earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now