Hi,

I'am not sure that i really understood whole problem but decided to prepare a 
small usefull code sample;



Function TForm1.ReconnectIfNotConnected : Boolean;    //Connection Control...

begin

    Result := False;

    if not (AdoConnection1.Connected) then

        try

            AdoConnection1.Connected := True;

              Result := True;

        except

                Showmessage('Connection error:' + #13#13#10 + 'Connection 
String : ' + AdoConnection1.ConnectionString );

        end;

end;



Function TForm1.RefreshSqlResult(sql : String; aq : TAdoQuery = AdoQuery1) : 
Boolean;   // Querying...

begin

    // using TAdoQuery whose Connection is TAdoConnection1.

    // use a DataSource whose dataset is TAdoQuery1 or aq which you already 
assigned.

    (aq as TAdoQuery).Active := False;


    (aq as TAdoQuery).Sql.text := sql;     

    try

        (aq as TAdoQuery).Active := True;

        Result := ((aq as TAdoQuery).RecordCount > 0 );

    except

        Showmessage('DB Error:' + #13#13#10 + 'Query  : ' + sql);

    end;      

end;


Procedure TForm1.UsefullCode;            // main functions...
var     sqls , OneStringField : String; Count : integer;
begin
    if ReconnectIfNotConnected then begin
        sqls := 'select * from Table';
        if RefreshSqlResult(sqls , AdoQuery1)  then begin

           { Finding record count}
           Count = AdoQuery1.RecordCount; 
                  {or}
          {Fetching dataset...}
            AdoQuery1.First;                                        
            While not AdoQuery1.eof do begin
                OneStringField := AdoQuery1.FieldByName('FieldName').Asstring;
                AdoQuery1.Next;
            end;
        end else begin
            Showmessage('No result found in query : ' + #13#13#10 + sqls);
       end;
    end;
end;




> > procedure Tform1.button1Click (Sender: Tobject);

> > Begin

> > Q1.close;

> > Q1.sql.clear;

> > Q1.sql.add(' select * from Table');

> > Q1.open;

> > Q1.RecordCount;

> > ClientDataSet1. open;        //Dups Q1.Query DataSet

> > Q1.close;  //Saving wear and tear on Server so running from Mem Buffer

> > ClientDataSet1. RecordCount; //1st try works properly

> >                             //later comes up empty even though

> >                             //Q1.RecordCount has increased

> >

> > //Do Things with ClientDataSet1/ /

> > ClientDataSet1. EmptyDataSet;

> > ClientDataSet1. close;

> > Form1.Button1. Click;  //Repeat until the cows come home

> >

> > //Tried removing the DataSet.close and adding ClientDataSet1. refresh

> > with same empty result set after 1st pass?//

> >

> > Any suggestions on properly refreshing the ClientDataSet1?

> >

> > Thanks so much!

> > Tony

----- Original Message ----
From: Tony1L <[EMAIL PROTECTED]>
To: advanced_delphi@yahoogroups.com
Sent: Tuesday, May 29, 2007 5:01:11 PM
Subject: [advanced_delphi] Re: ClientDataSet loop not refreshing with any 
records









  


    
            Thanks for the reply but alas this is not entirely the solution. 
I've

posted my code below.  Notice the lines (ClientDataSet1. Open;

ClientDataSet1. Close) but when it loops I'm not getting refreshed data

actually no records after it reopens.  Query's getting refreshed

during debug I have query.recordcount and can see the increased count

and can see that the ClientDataSet is being closed/opened but there's

some reason that it's not getting populated. Any other tips or

suggestions? 



--- In advanced_delphi@ yahoogroups. com, "Vo Viet Anh"

<vietanh1969@ ...> wrote:

>

>    Hi Tony,

> the orderly way to refresh a ClientDataset is to close it and open

again,  

> also:

> 

>    ClientDataSet1. Close;

>    ClientDataSet1. Open;

> 

> That's all!

> Don't bore with the Query, MIDAS will do it automatically (and

correctly)  

> for you.

> 

> BTW: I think such technique are clearly represented in the User

Manual and  

> online-help. Why not take a look?

> 

> Viet Anh

> 

> On Sat, 26 May 2007 04:22:57 +0700, Tony1L <[EMAIL PROTECTED]> wrote:

> 

> > I have a project where I'm repeatedly calling a Button.Click event in

> > which I'm using an ADOConnection to a MSSQL Database with Query and

> > also open a ClientDataSet with corresponding DataSetProvider directed

> > to the Query. Once it goes back through the code again ClientDataSet1

> > isn't receiving any records...even through I see them by checking

> >  Q1.RecordCount. On the second...third pass the ClientDataSet1

> > is set to 0?  What could I add to this to properly refresh the

dataset?

> >

> > Sample Code:

> > procedure Tform1.button1Click (Sender: Tobject);

> > Begin

> > Q1.close;

> > Q1.sql.clear;

> > Q1.sql.add(' select * from Table');

> > Q1.open;

> > Q1.RecordCount;

> > ClientDataSet1. open;        //Dups Q1.Query DataSet

> > Q1.close;  //Saving wear and tear on Server so running from Mem Buffer

> > ClientDataSet1. RecordCount; //1st try works properly

> >                             //later comes up empty even though

> >                             //Q1.RecordCount has increased

> >

> > //Do Things with ClientDataSet1/ /

> > ClientDataSet1. EmptyDataSet;

> > ClientDataSet1. close;

> > Form1.Button1. Click;  //Repeat until the cows come home

> >

> > //Tried removing the DataSet.close and adding ClientDataSet1. refresh

> > with same empty result set after 1st pass?//

> >

> > Any suggestions on properly refreshing the ClientDataSet1?

> >

> > Thanks so much!

> > Tony

> >

> >

> >

> 

> 

> 

> -- 

> Using Opera's revolutionary e-mail client: http://www.opera. com/mail/

>





    
  

    
    




<!--

#ygrp-mlmsg {font-size:13px;font-family:arial, helvetica, clean, sans-serif;}
#ygrp-mlmsg table {font-size:inherit;font:100%;}
#ygrp-mlmsg select, input, textarea {font:99% arial, helvetica, clean, 
sans-serif;}
#ygrp-mlmsg pre, code {font:115% monospace;}
#ygrp-mlmsg * {line-height:1.22em;}
#ygrp-text{
font-family:Georgia;
}
#ygrp-text p{
margin:0 0 1em 0;}
#ygrp-tpmsgs{
font-family:Arial;
clear:both;}
#ygrp-vitnav{
padding-top:10px;font-family:Verdana;font-size:77%;margin:0;}
#ygrp-vitnav a{
padding:0 1px;}
#ygrp-actbar{
clear:both;margin:25px 0;white-space:nowrap;color:#666;text-align:right;}
#ygrp-actbar .left{
float:left;white-space:nowrap;}
.bld{font-weight:bold;}
#ygrp-grft{
font-family:Verdana;font-size:77%;padding:15px 0;}
#ygrp-ft{
font-family:verdana;font-size:77%;border-top:1px solid #666;
padding:5px 0;
}
#ygrp-mlmsg #logo{
padding-bottom:10px;}

#ygrp-vital{
background-color:#e0ecee;margin-bottom:20px;padding:2px 0 8px 8px;}
#ygrp-vital #vithd{
font-size:77%;font-family:Verdana;font-weight:bold;color:#333;text-transform:uppercase;}
#ygrp-vital ul{
padding:0;margin:2px 0;}
#ygrp-vital ul li{
list-style-type:none;clear:both;border:1px solid #e0ecee;
}
#ygrp-vital ul li .ct{
font-weight:bold;color:#ff7900;float:right;width:2em;text-align:right;padding-right:.5em;}
#ygrp-vital ul li .cat{
font-weight:bold;}
#ygrp-vital a {
text-decoration:none;}

#ygrp-vital a:hover{
text-decoration:underline;}

#ygrp-sponsor #hd{
color:#999;font-size:77%;}
#ygrp-sponsor #ov{
padding:6px 13px;background-color:#e0ecee;margin-bottom:20px;}
#ygrp-sponsor #ov ul{
padding:0 0 0 8px;margin:0;}
#ygrp-sponsor #ov li{
list-style-type:square;padding:6px 0;font-size:77%;}
#ygrp-sponsor #ov li a{
text-decoration:none;font-size:130%;}
#ygrp-sponsor #nc {
background-color:#eee;margin-bottom:20px;padding:0 8px;}
#ygrp-sponsor .ad{
padding:8px 0;}
#ygrp-sponsor .ad #hd1{
font-family:Arial;font-weight:bold;color:#628c2a;font-size:100%;line-height:122%;}
#ygrp-sponsor .ad a{
text-decoration:none;}
#ygrp-sponsor .ad a:hover{
text-decoration:underline;}
#ygrp-sponsor .ad p{
margin:0;}
o {font-size:0;}
.MsoNormal {
margin:0 0 0 0;}
#ygrp-text tt{
font-size:120%;}
blockquote{margin:0 0 0 4px;}
.replbq {margin:4;}
-->








       
____________________________________________________________________________________Be
 a better Globetrotter. Get better travel answers from someone who knows. 
Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469

Reply via email to