在进行完update程序就关闭了.数据已经更新,以下是源码
procedure TForm1.Button2Click(Sender: TObject);
var get_date,csid:string;
l_avail,l_lqconsum,l_wfconsum,l_yfconsum,l_savail,l_sumavail:single;
year:integer;
bl:single;
querybox1:TQuery;
begin
if (edit1.text='') or (strtofloat(edit1.text)<30000) then
begin
showmessage('返还累计金额不能小于30000');
end;
if edit1.text='' then
begin
showmessage('请输入返还金额');
end
else
begin
querybox1:=TQuery.Create(nil);
with querybox1 do
get_date:=datetostr(date);
l_avail:=strtofloat(edit5.text);
l_lqconsum:=strtofloat(edit1.text);
csid:=edit3.Text;
bl :=strtofloat(edit2.text);
end;
if csid='' then
begin
showmessage('请选择会员')
end
else
begin
close;
querybox1.DatabaseName:='ww';
querybox1.SQL.clear;
querybox1.SQL.Add('update cs_zzk set j_wfconsum=j_wfconsum-:l_lqconsum ,j_yfconsum=j_yfconsum+:l_lqconsum,f_avail=:l_avail,f_consum=f_consum+:l_avail');
querybox1.SQL.Add('where cs_id=:csid');
querybox1.params[0].asfloat:=l_lqconsum;
querybox1.params[1].asfloat:=l_lqconsum;
querybox1.params[2].asfloat:=l_avail;
querybox1.params[3].asfloat:=l_avail;
querybox1.params[4].asstring:=csid;
try
querybox1.ExecSQL;
except
close;
Free;
queryBox1 := nil;
exit;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var get_date,csid:string;
l_avail,l_lqconsum,l_wfconsum,l_yfconsum,l_savail,l_sumavail:single;
year:integer;
bl:single;
querybox1:TQuery;
begin
if (edit1.text='') or (strtofloat(edit1.text)<30000) then
begin
showmessage('返还累计金额不能小于30000');
end;
if edit1.text='' then
begin
showmessage('请输入返还金额');
end
else
begin
querybox1:=TQuery.Create(nil);
with querybox1 do
get_date:=datetostr(date);
l_avail:=strtofloat(edit5.text);
l_lqconsum:=strtofloat(edit1.text);
csid:=edit3.Text;
bl :=strtofloat(edit2.text);
end;
if csid='' then
begin
showmessage('请选择会员')
end
else
begin
close;
querybox1.DatabaseName:='ww';
querybox1.SQL.clear;
querybox1.SQL.Add('update cs_zzk set j_wfconsum=j_wfconsum-:l_lqconsum ,j_yfconsum=j_yfconsum+:l_lqconsum,f_avail=:l_avail,f_consum=f_consum+:l_avail');
querybox1.SQL.Add('where cs_id=:csid');
querybox1.params[0].asfloat:=l_lqconsum;
querybox1.params[1].asfloat:=l_lqconsum;
querybox1.params[2].asfloat:=l_avail;
querybox1.params[3].asfloat:=l_avail;
querybox1.params[4].asstring:=csid;
try
querybox1.ExecSQL;
except
close;
Free;
queryBox1 := nil;
exit;
end;
end;
end;
close; //试问你的这个Close是窗口的Close还是Querybox1的Close;
querybox1.DatabaseName:='ww';
querybox1.SQL.clear;
还有如下写法有时也忌讳
with query1,Query2 do
begin
Close;//是两个都要操作吗?
SQL.Clear;
...
end.
仅此例子,不要效仿。