Recent

Author Topic: Using two querys  (Read 4689 times)

cpalx

  • Hero Member
  • *****
  • Posts: 647
Using two querys
« on: March 07, 2007, 08:00:53 pm »
Hello
I am using Lazarus 0.9.20 on windows XP SP2, and I have a SQLserver2000 conexion in other machine. The conexion is great, when i do a Query works fine, but I need to use another query using a field from the first and shows me an erro which message is :

The conexion is busy qith other results (i don't know if the traduction is ok)

Just to say i am usig two querys conected in two datasources (each other) and then with the same ODBCconecction and one transsaction.

i hope i wrote is ok and understood

thans

CpaLX

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: Using two querys
« Reply #1 on: March 08, 2007, 05:56:01 pm »
After you open the First query call the Last method and then the First again in order to buffer all the data from the first query before you try to open the second query.

Code: [Select]

  Query1.DisableControls;
  try
    Query1.Open;
    Query1.Last;
    Query1.First;
  finally
    Query1.EnableControls;
  end;
  Query2.Open;
The FRED Trainer. (Training FRED with Lazarus/FPC)

cpalx

  • Hero Member
  • *****
  • Posts: 647
Using two querys
« Reply #2 on: March 08, 2007, 11:32:01 pm »
The problem is with that i lost the position of my query. What i need is something like this :

**********************************

function TfrmTramas.EjecutaSQL(Sender: TObject; sSQL: String; Opcion: Byte):Boolean;
Begin
if Opcion =0 then
     with SQLQuery do
     Begin
          Close; SQL.Clear; SQL.Text:= sSQL; Prepare; Open;
     End
Else
     with SQLQueryX do
     Begin
          Close; SQL.Clear; SQL.Text:= sSQL; Prepare; Open;
     End

End;


Function TfrmTramas.date_(Sender: TObject;Seguro: ShortInt):String;
....
Consulta := 'select pa.pacres as CodPacAsegurado, '+ //CodPacAsegurado
                      'pa.pachis as NumHisClinica, ' +     //NumHisClinica
                      'pf.oricod as TipoAtencion, ' +       //TipoOriAten
                      'prffin FechIniAten, '  +            //FechIniAten
                      'me.medcol as CodProfRes, '+         //CodProfRes
                      'me.sercod as EspePrinAten, '+       //EspePrinAten
                      'pf.plnded as CoPagofijo, ' +        //CoPagofijo
                      '(pf.plncoa/100)* prftot as CoPagovar, '+  // CoPagovar
                      'fa.factot as MontoCubAten ' +        //MontoCubAten
                 'from prefacturas as pf, '+
                      'pacientes as pa, ';
EjecutaSQL(Sender,Consulta,0);

while NOT SQLQuery.EOF do
Begin
consulta2 := '..............'+
                  'where SomeField=' + SQLQuery.FieldByName['CoPagofijo'].asString;
EjecutaSQL(Sender,Consulta,1);
SQLQuery.Next;
End

**********************************

RudieD

  • Full Member
  • ***
  • Posts: 234
Using two querys
« Reply #3 on: March 09, 2007, 03:57:17 pm »
I would suggest to do the Last/First in the OnAfterOpen event of the query so that it then cashes it as soon as it opens ?
The FRED Trainer. (Training FRED with Lazarus/FPC)

cpalx

  • Hero Member
  • *****
  • Posts: 647
Using two querys
« Reply #4 on: March 12, 2007, 09:38:45 pm »
Thanks, now works great

 

TinyPortal © 2005-2018