[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Grid & SQL

Posted on 2002-06-28
4
Medium Priority
?
258 Views
Last Modified: 2010-04-04
I have a Grid that has been populated with information retrieved via a SQL query.

I want to be able to multi-select or use a check-box to select only the records I want to use.

When I have chosen my records I then need to find a way of sending only those records selected to a table.

Any ideas??
Thanks
0
Comment
Question by:HotRod40
[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
  • 3
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7115954
thats easy,

sample follows in some hours,
because i have a ready sample,
but just not here

therefore just some hints

set the rowselect and multiselect-options of the gris to true
after selection, iterate through the selected rows

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7116245
here it comes,
sorry its not commented/explained

just ask, if unclear

two grids, where the selected rows are transfered to another table

unit uebertrag_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBTables, Grids, DBGrids, Db, ExtCtrls, ComCtrls, Buttons, DBCtrls,
  StdCtrls;

type
  TUForm = class(TForm)
    QSource: TQuery;
    DSSource: TDataSource;
    DDest: TDBGrid;
    TDest: TTable;
    DSDest: TDataSource;
    DSource: TDBGrid;
    Sp: TSplitter;
    Panel1: TPanel;
    StatusBar: TStatusBar;
    DBN: TDBNavigator;
    UB: TSpeedButton;
    CB: TComboBox;
    In1: TEdit;
    In2: TEdit;
    Label1: TLabel;
    RR: TSpeedButton;
    SBUP: TSpeedButton;
    SBDN: TSpeedButton;
    TDestTmp: TTable;
    procedure SpMoved(Sender: TObject);
    procedure UBClick(Sender: TObject);
    procedure RRClick(Sender: TObject);
    procedure DSourceKeyPress(Sender: TObject; var Key: Char);
    procedure FormResize(Sender: TObject);
    procedure SBUPClick(Sender: TObject);
    procedure SBDNClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  UForm: TUForm;

implementation

{$R *.DFM}

procedure TUForm.SpMoved(Sender: TObject);
begin
  If Sp.left - UB.Width > 0 Then
    UB.Left := Sp.left - (UB.Width div 2)
  else
    UB.Left := 0;
end;

procedure TUForm.UBClick(Sender: TObject);
var i,j : Integer;
begin
  if DSource.SelectedRows.Count > 0 then
  begin
    for j := 0 to DSource.SelectedRows.Count - 1 do
    begin
      QSource.GotoBookmark(TBookMark(DSource.SelectedRows.Items[J]));
      TDest.Append;
      For i := 0 to QSource.FieldCount - 1 do
        TDest.Fields[i] := QSource.Fields[I];
      TDest.Post;
    end;
  end;
end;



procedure TUForm.RRClick(Sender: TObject);
const SQLs = 'select name, adrl1, street, zip, city, state from adressen';
var s : String;
begin
  QSource.DisableControls;
  QSource.Active := False;
  QSource.SQL.Clear;
  If CB.Text = '' Then S := ''
  else
    s := ' where '+CB.Text+' between "'+In1.Text+'" and "'+In2.Text+'"';
  QSource.SQL.Add(SQLs+s);
  Try
    QSource.Active := True;
  except
    Showmessage('Eingabefehler ! Startzustand wird wieder hergestellt ! Statement = '+SQLs+S);
    QSource.Active := False;
    QSource.SQL.Clear;
    QSource.SQL.Add(SQLs);
    QSource.Active := True;
  end;
  QSource.EnableControls;
end;

procedure TUForm.DSourceKeyPress(Sender: TObject; var Key: Char);
begin
  If Key = #13 then UBClick(Self);
end;

procedure TUForm.FormResize(Sender: TObject);
begin
  SBUP.Left := DBN.Left - 50;
  SBDN.Left := DBN.Left - 25;
end;

procedure TUForm.SBUPClick(Sender: TObject);
var i : Integer;
begin
  TDestTmp.GotoCurrent(TDest);
  TDestTmp.Prior;
  TDestTmp.Insert;
  For i := 0 to TDest.FieldCount - 1 do
    TDestTmp.Fields[i] := TDest.Fields[I];
  TDest.Delete;
  TDest.GotoCurrent(TDestTmp);
end;

procedure TUForm.SBDNClick(Sender: TObject);
var i : Integer;
begin
  TDestTmp.GotoCurrent(TDest);
  TDestTmp.Next;
  TDestTmp.Next;
  If not TDestTmp.EOf then
  begin
    TDestTmp.Insert;
    For i := 0 to TDest.FieldCount - 1 do
      TDestTmp.Fields[i] := TDest.Fields[I];
    TDest.Delete;
    TDest.GotoCurrent(TDestTmp);
  end;
end;

end.


hope this helps

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 225 total points
ID: 7116403
just to point out what you need, i guess

procedure TUForm.UBClick(Sender: TObject);
var i,j : Integer;
begin
 if DSource.SelectedRows.Count > 0 then
 begin
   for j := 0 to DSource.SelectedRows.Count - 1 do
   begin
     QSource.GotoBookmark(TBookMark(DSource.SelectedRows.Items[J]));
     TDest.Append;
     For i := 0 to QSource.FieldCount - 1 do
       TDest.Fields[i] := QSource.Fields[I];
     TDest.Post;
   end;
 end;
end;


meikl ;-)
0
 

Author Comment

by:HotRod40
ID: 7121806
Thanks but theres one more thing.

I want to be able to update a field but only with the records that have been selected.
How can I do this?

I have tried your example above and it works great with a Select SQL query. I have tried it with an Update SQL query and it says the dataset is not open even though I have actually called the ExecSQL command.

Can I not use an Update within this loop that you have demonstrated for me??

Thanks
Scott
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 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