Hello, I have an order form for a distributor, it has the associated customer, the details of the order products, and the order ID in a DBEDit. The initial idea of the form is that when creating it (opening it from the main one) the last created order ID appears, that is, the last one loaded.
I have in the OnCreate event the following:
procedure TPEDIDO.FormCreate(Sender: TObject);
var
idpedido: Integer;
begin
Position := poScreenCenter;
// obtengo el pedido actual
if DBEdit1.Text <> '' then
begin
// hago la consulta con este id y obtengo el detalle
idpedido := StrToInt(DBEdit1.Text);
DataModule1.qdetpedido.Close;
DataModule1.qdetpedido.ParamByName('idp').AsInteger := idpedido;
DataModule1.qdetpedido.ExecSQL();
end;
// edito el dataset de cliente para mostrar el nombre en el dbedit
DataModule1.cdscp.Edit;
DataModule1.cdscpIdCliente.AsInteger :=
DataModule1.cdspedidosIdCliente.AsInteger;
DataModule1.cdsproductos.First;
// agrego los codigos de articulos a las columnas
while not DataModule1.cdsproductos.eof do
begin
PEDIDO.gpedidotemp.Columns[2].PickList.Add
(DataModule1.cdsproductosCodigo.AsString);
PEDIDO.gpedidotemp.Columns[3].PickList.Add
(DataModule1.cdslistasNombre.AsString);
DataModule1.cdsproductos.Next;
end;
end;
As you can see, "qdetpedido" is a TSQLQuery (I work with MySQL) that has an "idp" parameter, which is the idpedido to fetch its data. The query is as follows:
select * from detallepedido where detallepedido.Idpedido=:idp;
I have a DBEdit to display the name of the associated client, what I am trying to do is position the DataSet cursor so that the name appears, but it does not work either.
And lastly, I charge the alphanumeric codes in the form of a combo in the "gpedidotemp" grid, but the details do not appear.
With the current code in your question, you are technically not displaying the records that are in the database, but rather creating new records in the order detail ClientDataSet . If you call the method
ApplyUpdates
, these records will be added to what exists in the database.Since you use a Provider to connect the SQLQuery to the ClientDataSet , to display the records that are in the database, you can pass the request id parameter using that provider .
Finally, I would make a method that retrieves a complete request from the database, so that we make sure that the DataSets that represent it in memory will always be synchronized , something like:
And then you would call that method from the form, for example: