search button lazarus / 13-General ---------------------------------------------------------------------- arai · 2009-06-05 17:10 I created a button for doing a search and inserting the data on a stringgrid the code the thanked was this var    sql : String; begin      SQLTransaction.Active:=true;      sql := 'SELECT * FROM servico  WHERE 1=1';      sql := sql + ' AND num='+NumeroServico.Text;      sql := sql + ' AND kms_e='+KmsEntrada.Text;      sql := sql + ' AND kms_s='+KmsdeSaida.Text;      sql := sql + ' AND data_e='''+DatadeEntrada.Text+'''';      sql := sql + ' AND data_s='''+DatadeSaida.Text+'''';      sql := sql + ' AND matricula='''+MatriculaServico.Text+'''';      sql := sql + ' AND emp_responsavel='''+EmpregadoResponsavel.Text+'''';      sql := sql + ' AND horas='+HorasServico.Text;      SQLQuery.SQL.Text:=sql;      SQLQuery.Open;   //introduz na string grid os respectivos valores   SGservico.RowCount := 1;   while not SQLQuery.EOF do begin         SGservico.RowCount := SGservico.RowCount + 1;         SGservico.Cells[0, SGservico.RowCount - 1] := SQLQuery.Fields[0].Text;         SGservico.Cells[1, SGservico.RowCount - 1] := SQLQuery.Fields[1].Text;         SGservico.Cells[2, SGservico.RowCount - 1] := SQLQuery.Fields[2].Text;         SGservico.Cells[3, SGservico.RowCount - 1] := SQLQuery.Fields[4].Text;         SGservico.Cells[4, SGservico.RowCount - 1] := SQLQuery.Fields[5].Text;         SGservico.Cells[5, SGservico.RowCount - 1] := SQLQuery.Fields[6].Text;         SGservico.Cells[6, SGservico.RowCount - 1] := SQLQuery.Fields[3].Text;         SGservico.Cells[7, SGservico.RowCount - 1] := SQLQuery.Fields[8].Text;         SQLQuery.Next;    end;    SQLQuery.Close;    SQLTransaction.Active := false; if anyone can tell me what i'm doing wrong? please helo me. Thanks ---------------------------------------------------------------------- marquessbr · 2009-06-05 18:56 if you can tell us who is giving error, maybe we can help you ... peace! ---------------------------------------------------------------------- arai · 2009-06-08 08:08 Is giving me a sql error near of AND, the first AND, SQLQuery preparation failed something like this. I use this way, because it was recommended by the person who i have to give the project. He tried to explain me how to do it, but he was so much hurry that only give me some topics. And i did like i understand, but isn't the right way like i'm seeing. Thanks for your help. ---------------------------------------------------------------------- marquessbr · 2009-06-09 11:06 try this: procedure TMyForm.Button2Click(Sender: TObject); var sql:string; begin {...}sql := 'SELECT * FROM servico  WHERE 1=1 AND num='+Quotedstr(NumeroServico.Text)+ {...}' AND kms_e='+Quotedstr(KmsEntrada.Text)+ {...}' AND kms_s='+Quotedstr(KmsdeSaida.Text)+ {...}' AND data_e='+Quotedstr(DatadeEntrada.Text)+ {...}' AND data_s='+Quotedstr(DatadeSaida.Text)+ {...}' AND matricula='+Quotedstr(MatriculaServico.Text)+ {...}' AND emp_responsavel='+Quotedstr(EmpregadoResponsavel.Text)+ {...}' AND horas='+Quotedstr(HorasServico.Text); {...}ZQuery1.SQL.Text:=sql; {...}ZQuery1.Open; end; I use a Zeos conecction and a ZQuery and compile and open de query ok, all work fine. I hope with solve your problem. peace