我的代码就是这样写的 Edit和Post都在循环外
代码如下 您请看看有什么不妥
with QueryPole do
begin
close;
commandText := 'select count(*) DGZSL,sStuff from pd_d_hvolpole where sFeederName1='''+sLineSid+''' group by sStuff';
try
open;
//first;
if DataSetBroker1.DataSet.Active then DataSetBroker1.DataSet.Close;
DataSetBroker1.DataSet.Open;
DataSetBroker1.DataSet.Edit;
while not eof do
begin
//根据电杆材质编码得到电杆的材质
tempSQLStr := 'select sPoleTextrue from PD_P_POLETEXTURE where sId='''+FieldByName('sStuff').AsString+'''';
if ReturnSQLValue(Query1,tempSQLStr,'sPoleTextrue') <> '' then
begin
DGCZ := ReturnSQLValue(Query1,tempSQLStr,'sPoleTextrue');
end
else
begin
//如果查找电杆材质为空,则该电杆的材质显示为'未知'
DGCZ := '未知';
end;
DGCZSL := StoI(FieldByName('DGZSL').AsString);
DGZSL := DGZSL+StoI(FieldByName('DGZSL').AsString);
//DataSetBroker1.DataSet.Edit;
DataSetBroker1.DataSet.FieldByName('DGCZ').Value := DGCZ;
DataSetBroker1.DataSet.FieldByName('DGCZSL').Value := DGCZSL;
DataSetBroker1.DataSet.FieldByName('DGZSL').Value := DGZSL;
DataSetBroker1.DataSet.Next;
next;
end
finally
close;
end;
DataSetBroker1.DataSet.Post;
DataSetBroker1.DataSet.ApplyUpdates;
DataSetBroker1.DataSet.Close;
end; |