PDA

Ver la Versión Completa : ADO, problema con commit


Gaim2205
23-10-2007, 19:34:55
tengo mi aplicacion con d7, sql server 2000, y me conecto con los ADO, pero por mas commits que le doy, el insert o update solo tiene efecto hasta la proxima vez que inicio la aplicacion. La verdad nunca habia utilizado los ADO asi que muy probablemente estoy poniendo mal el begintrans y commit trans.

aqui esta el codigo, ojala me puedan ayudar. Gracias


begin
ADOConnection1.BeginTrans;
valida();
if valida = true then
begin
ds_precios.DataSet.Locate('combo',combo,[]);
fcombo := ds_precios.DataSet.fieldByName('combo').AsInteger;
fdate := ds_precios.DataSet.fieldByName('fecha').AsDateTime;
if (fcombo = combo) and (fdate = fecha.Date) then
begin
showmessage(IntToStr(combo));
pre := ds_precios.DataSet.FieldByName('precio').AsFloat;
opc := MessageDlg('Este producto está registrado en la misma fecha con el precio: '+FloatToStr(pre)+' ,Sobreescribir?',mtWarning, mbOKCancel, 0);
if opc = mrCancel then BitBtn2.Click
else
with que_fecha do begin
with Parameters do begin
ParamByName('price').Value := StrToFloat(precio.Text);
ParamByName('combo').Value := combo;
Parameters.ParamByName('date').Value := fecha.Date;
end;
ExecSQL;
ADOConnection1.CommitTrans;
ADOQuery1.Close; ADOQuery1.Open;
DBGrid1.Refresh;
especie.Text := ''; espesor.Text := '';
clase.Text := ''; precio.Clear;
fecha.Clear;
end; end
else
begin
showmessage(IntToStr(combo));
showmessage(fecha.Text);
que_captura.SQL.Clear;
que_captura.SQL.Add('select count(id) from pocapprc_sql');
que_captura.Open;
gen_id := que_captura.Fields[0].AsInteger;
gen_id := gen_id+1;
with que_captura do begin
sql.Clear;
sql.Add('insert into pocapprc_sql(id,precio,fecha,combo)');
sql.Add('values(:id,:precio,:fecha,:combo)');
with Parameters do begin
ParamByName('id').Value := gen_id;
ParamByName('precio').Value := StrToFloat(precio.Text);
ParamByName('fecha').Value := fecha.Date;
ParamByName('combo').Value := combo;
end;
ExecSQL;
ADOConnection1.CommitTrans;
ADOQuery1.Close; ADOQuery1.Open;
DBGrid1.Refresh;
especie.Text := ''; espesor.Text := '';
clase.Text := ''; precio.Clear;
fecha.Clear;
end; end; end
else
MessageDlg('Favor de introducir todos los datos',mtWarning, [mbOK], 0);
end;

Caral
23-10-2007, 19:41:06
Hola
Mas o menos por aqui (http://www.clubdelphi.com/foros/showthread.php?t=49478) anda la cosa.
Revisado, cualquier duda, la comentas.
Saludos

Gaim2205
23-10-2007, 20:01:29
se solucionó con un simple refresh en las tablas, que no se porque no me lo hacia hasta que reinicie delphi.

danke