我把你的代码简化了一下, 你看看行不行.procedure TF_qsgs.ComboBox1Change(Sender: TObject); Var i:integer; begin With Yp_data.Query1 Do Begin Close; Sql.Clear; Sql.Add('select * from modual_zb where no='''+Copy(ComBoBox1.text,1,4)+''' order by zbno'); Open; Stringgrid1.RowCount:=1; i:=0; While Not Eof Do Begin Inc(i); Stringgrid1.RowCount:=Stringgrid1.RowCount+1; Stringgrid1.Cells[0,i]:=FieldByname('zbno').Asstring; Stringgrid1.Cells[1,i]:=FieldByname('zbname').Asstring; Stringgrid1.Cells[2,i]:=FieldByname('formual').Asstring; Next; End; End; end
Var
i:integer;
begin
With Yp_data.Query1 Do
Begin
Close;
Sql.Clear;
Sql.Add('select * from modual_zb where no='''+Copy(ComBoBox1.text,1,4)+''' order by zbno');
Open;
Stringgrid1.RowCount:=1;
i:=0;
While Not Eof Do
Begin
Inc(i);
Stringgrid1.RowCount:=Stringgrid1.RowCount+1;
Stringgrid1.Cells[0,i]:=FieldByname('zbno').Asstring;
Stringgrid1.Cells[1,i]:=FieldByname('zbname').Asstring;
Stringgrid1.Cells[2,i]:=FieldByname('formual').Asstring;
Next;
End;
End;
end