Recent

Author Topic: How to get from stringgrid list to sql bd?  (Read 7397 times)

arai

  • Newbie
  • Posts: 4
How to get from stringgrid list to sql bd?
« on: June 05, 2009, 07:06:44 pm »
hello

I'm trying do get more then a line from sg,
i tried to use this code:
      PQConnection.ExecuteDirect('Begin Work');
      PQConnection.ExecuteDirect('INSERT INTO servico VALUES(DEFAULT,'+KmsEntrada.Text+','+KmsdeSaida.Text+','''+EmpregadoResponsavel.Text+''','''+DatadeEntrada.Text+''','''+DatadeSaida.Text+''','''+MatriculaServico.Text+''','+nif+','+HorasServico.Text+')');

      WHILE NOT EOF do begin
      SGpecasutilizadas.RowCount:=1;
      PQConnection.ExecuteDirect('INSERT INTO pecasutilizadas VALUES('''+SGpecasutilizadas.Cells[0, SGpecasutilizadas.RowCount]+''','+NumeroServico.Text+')');
      SGpecasutilizadas.RowCount:= SGpecasutilizadas.RowCount + 1;
      end;

      PQConnection.ExecuteDirect('Commit Work');
      ActualizarServico(); 


on the table servico is inserting values right, but on the table pecasusadas isn't,
shure is something very wrong.
Like you allready have repair i'm a noob on this.

So please help me.
Thanks

Loesje

  • Full Member
  • ***
  • Posts: 165
    • Lazarus Support website
Re: How to get from stringgrid list to sql bd?
« Reply #1 on: June 07, 2009, 04:59:13 pm »
At a first glance I don't see anything wrong.

But '+NumeroServico.Text+' has no quotes around it, and the name .Text implies that it is a string, and not a number?

But in that case you should get an error.

And maybe you should gemove the 'begin work' and 'end work' lines. And add Transaction.Commit, which handles the transaction for you.

arai

  • Newbie
  • Posts: 4
Re: How to get from stringgrid list to sql bd?
« Reply #2 on: June 08, 2009, 10:01:35 am »
'Numero.Text' is a number so i don't have any error on this, but doesn't put anything on the table pecasusadas. And i don't understand why.
I didn't understand what you mean when you said to add Transaction.Commit. I don't know this instruction. How should used?
Thanks for your help.

jesusr

  • Sr. Member
  • ****
  • Posts: 470
Re: How to get from stringgrid list to sql bd?
« Reply #3 on: June 08, 2009, 05:42:09 pm »
      WHILE NOT EOF do begin
      SGpecasutilizadas.RowCount:=1;
      PQConnection.ExecuteDirect('INSERT INTO pecasutilizadas VALUES('''+SGpecasutilizadas.Cells[0, SGpecasutilizadas.RowCount]+''','+NumeroServico.Text+')');
      SGpecasutilizadas.RowCount:= SGpecasutilizadas.RowCount + 1;
      end;

      PQConnection.ExecuteDirect('Commit Work');
      ActualizarServico(); 

It looks like the cycle is not well defined here, even if we assume EOF is from some "with dataset do ..." there is no next to advance for next record, now, within the cycle the first thing done is SGpecasutilizadas.RowCount:=1; which will let the grid with just one record (if there are fixed rows, then it's the first fixed row), even when at the end of cycle rows are increased. I think simply moving the first SGpecasutilizadas.RowCount:=1; before of cycle should do it.

 

TinyPortal © 2005-2018