DB:오라클 delphi:델파이5.0
스트링그리드의 이름은 sg
스트링그리드 초기 내용
(0,0) a1 a2 a3 s1 s2 s3 t1 t2
F
M
위와같이 되어있습니다.... col부분은 상품별코드구염 row부분은 남,녀를 나타내는 것인데염....쿼리문을 써서 상품이랑 성별로 그룹바이를 해서 각각 다음과 같은결과가 나왔습니다...
sex item price
F a1 40000
F a2 55000
F a3 25000
F s1 99000
F s3 161100
F t2 89000
M a1 30000
M s2 65100
이렇게 결과가 나왔는데염....이결과를 스트링그리드에 다음과 같이 맞춰서 넣어줄려구하거든여....
(0,0) a1 a2 a3 s1 s2 s3 t1 t2
F 40000 55000 25000 99000 0 161100 0 89000
M 30000 0 0 0 65100 0 0 0
이렇게염...쿼리에서 자료에 없는건 0으로 들어가게 할려구하거든여....
그래서....
제가 다음과 같이 했는데염......
first;
for k:=0 to sg.colcount-1 do begin
for y:=0 to sg.RowCount-1 do begin
if sg.Cells[0,k]=FieldByName('item').asstring then
begin
if sg.Cells[y,0]= FieldByName('sex').asstring then
begin
sg.cells[y,k]:= inttostr(FieldByName('price').asinteger) ;
end;
end
else
sg.cells[y,k]:='0';
end;
next;
end;
이케했더니....스트링 그리드전부가 0으루 되는거있져....--;
어케해야할지 답변부탁합니다.........
첨에 First를 하시고 For문 안에서 next를 하셔서 Grid의 Col을 1증가 시킬때 마다Next 동작이 이루어지게 되어있는데 그러면 현위치의 Col에서는 이전의 DB Record의
내용을 읽어들일 수가 없습니다. 그럼 원하지 않는 결과가 생길수 있죠.
First;
while Not EOF do begin
for k:=0 to sg.colcount-1 do begin
for y:=0 to sg.RowCount-1 do begin
if sg.Cells[0,k]=FieldByName('item').asstring then begin
if sg.Cells[y,0]= FieldByName('sex').asstring then begin
sg.cells[y,k]:= inttostr(FieldByName('price').asinteger) ;
end;
end
else
sg.cells[y,k]:='0';
end;
end;
next;
end;
이렇게 한번 해보시고 즐푸하세염......
노력중인초보 wrote:
> DB:오라클 delphi:델파이5.0
>
> 스트링그리드의 이름은 sg
> 스트링그리드 초기 내용
> (0,0) a1 a2 a3 s1 s2 s3 t1 t2
> F
> M
> 위와같이 되어있습니다.... col부분은 상품별코드구염 row부분은 남,녀를 나타내는 것인데염....쿼리문을 써서 상품이랑 성별로 그룹바이를 해서 각각 다음과 같은결과가 나왔습니다...
>
> sex item price
> F a1 40000
> F a2 55000
> F a3 25000
> F s1 99000
> F s3 161100
> F t2 89000
> M a1 30000
> M s2 65100
>
> 이렇게 결과가 나왔는데염....이결과를 스트링그리드에 다음과 같이 맞춰서 넣어줄려구하거든여....
>
> (0,0) a1 a2 a3 s1 s2 s3 t1 t2
> F 40000 55000 25000 99000 0 161100 0 89000
> M 30000 0 0 0 65100 0 0 0
>
> 이렇게염...쿼리에서 자료에 없는건 0으로 들어가게 할려구하거든여....
> 그래서....
>
> 제가 다음과 같이 했는데염......
> first;
>
> for k:=0 to sg.colcount-1 do begin
> for y:=0 to sg.RowCount-1 do begin
>
> if sg.Cells[0,k]=FieldByName('item').asstring then
> begin
> if sg.Cells[y,0]= FieldByName('sex').asstring then
> begin
> sg.cells[y,k]:= inttostr(FieldByName('price').asinteger) ;
> end;
> end
> else
> sg.cells[y,k]:='0';
> end;
> next;
>
> end;
>
> 이케했더니....스트링 그리드전부가 0으루 되는거있져....--;
> 어케해야할지 답변부탁합니다.........