可以实现给dbgrid的一个列填充么?该怎么处理
可以实现给dbgrid的一个列填充么?
begin
adoquery2.Close;
adoquery2.SQL.Text:='select productid,sum(number)as number from orders where shenhe=1 and jiaohuo=0 group by productid';
adoquery2.Open;
while not adoquery2.eof do
begin
s:=adoquery2.Fields[0].asstring;
t:=adoquery2.Fields[1].AsInteger;
adoquery1.Edit;
adoquery1.Post;
adoquery1.SQL.Add('select productid,productname,'''' as xuqiu,number from products where productid=:p1');
adoquery1.open;
adoquery1.Parameters.ParamByName('p1').Value:=s;
adoquery1.FieldByName('xuqiu').AsInteger:=t;
adoquery2.Next;
end;
这运行了还是错。。
------解决方案--------------------
逻辑混乱
adoquery1.Edit后什么都不做,下面你又post,没有意义
这一句之前要adoquery1.Close,然后最好加一句adoquery1.SQ.Clear,接着不要急着adoquery1.open;
把参数赋值完再open
begin
adoquery2.Close;
adoquery2.SQL.Text:='select productid,sum(number)as number from orders where shenhe=1 and jiaohuo=0 group by productid';
adoquery2.Open;
while not adoquery2.eof do
begin
s:=adoquery2.Fields[0].asstring;
t:=adoquery2.Fields[1].AsInteger;
adoquery1.Edit;
adoquery1.Post;
adoquery1.SQL.Add('select productid,productname,'''' as xuqiu,number from products where productid=:p1');
adoquery1.open;
adoquery1.Parameters.ParamByName('p1').Value:=s;
adoquery1.FieldByName('xuqiu').AsInteger:=t;
adoquery2.Next;
end;
这运行了还是错。。
------解决方案--------------------
逻辑混乱
adoquery1.Edit后什么都不做,下面你又post,没有意义
adoquery1.SQL.Add('select productid,productname,'''' as xuqiu,number from products where productid=:p1');
这一句之前要adoquery1.Close,然后最好加一句adoquery1.SQ.Clear,接着不要急着adoquery1.open;
把参数赋值完再open