用cxgrid遍歷來修改資料,是用ado的eof,和cxGrid1DBTableView1.DataController.IsEOF ,cxGrid1DBTableView1.Controller.FocusedRow.IsLast 來判斷是否到末位,但還是越界了,求各位大大看看
procedure TfrmBatchExtend.sbtnExtendClick(Sender: TObject);
var
rowIndex: Integer;
q: TADOQuery;
sDate, sName, s: string;
f: TIniFile;
begin
if (eExtend.Text = '0') or (eExtend.Text = '') then
begin
ShowMessage('延期月份最少為1個月');
Exit;
end;
f := TIniFile.Create(ExtractFilePath('D:\APark\APark.adf'));
sName := f.ReadString('Options','LastUser','0001');
q := TADOQuery.Create(Self);
q.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + b_sPassword + ';Persist Security Info=True;User ID=sa;Initial Catalog=APark;Data Source=' + b_sDBServer;
q.SQL.Text := 'select * from T1_Operator where mID = '+sName+'';
q.Open;
sName := q.FieldByName('Name').AsString;
q.Close;
q.SQL.Text := '';
with qryBatch do
begin
if not Active then
Open;
rowIndex := 0;
First;
while not Eof do
begin
if cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = null then
Exit;
if cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '1' then
begin
Edit;
//t3表修改有效期,t4表插入一條記錄
if FieldByName('Expiry').AsString = '' then
FieldByName('Expiry').AsDateTime := Now;
sDate := FieldByName('Expiry').AsString;
FieldByName('Expiry').AsDateTime := IncMonth(FieldByName('Expiry').AsDateTime,StrToInt(edtTemp.Text));
q.SQL.Add(' insert into t4_fee(mID,DateTime,FeeType,ExtendStart,ExtendEnd,FeeIndeed,FeeShould,Operator) '+
'values('+FieldByName('mid').AsString+',getdate(),3,cast('+sDate+' as datetime)'+
',cast('+FieldByName('Expiry').AsString+' as datetime),'+eFeeTotal.Text+','+eFeeTotal.Text+','''+sName+''')');
q.ExecSQL;
end;
if (cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '0') or
(cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '1') then
Next;
Inc(rowIndex);
if cxGrid1DBTableView1.DataController.IsEOF then
Exit;
if cxGrid1DBTableView1.Controller.FocusedRow.IsLast then
Exit;
end;
Edit;
UpdateBatch(arAll);
q.Destroy;
end;
end;
uj5u.com熱心網友回復:
if (cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '0') or(cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '1') then
Next;
Inc(rowIndex);
每次不一定都執行了qrybatch.next; 但rowindex每次+1,在QRY.EOF=TRUE時,rowindex就會越界!!
uj5u.com熱心網友回復:
因為需要進行group by,所以會多出group by 的行數,只能跳過去不賦值
uj5u.com熱心網友回復:
你的資料集回圈結構有問題1、要充分利用資料集的Eof判斷陳述句。
2、你的陳述句已到尾部,繼續讀入資料的錯誤。
3、Next執行不應加入條件,這樣會造成回圈的不同步。
建議以下試試:
procedure TfrmBatchExtend.sbtnExtendClick(Sender: TObject);
var
rowIndex: Integer;
q: TADOQuery;
sDate, sName, s: string;
f: TIniFile;
begin
if (eExtend.Text = '0') or (eExtend.Text = '') then
begin
ShowMessage('延期月份最少為1個月');
Exit;
end;
f := TIniFile.Create(ExtractFilePath('D:\APark\APark.adf'));
sName := f.ReadString('Options','LastUser','0001');
q := TADOQuery.Create(Self);
q.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + b_sPassword + ';Persist Security Info=True;User ID=sa;Initial Catalog=APark;Data Source=' + b_sDBServer;
q.SQL.Text := 'select * from T1_Operator where mID = '+sName+'';
q.Open;
sName := q.FieldByName('Name').AsString;
q.Close;
q.SQL.Text := '';
with qryBatch do
begin
if not Active then
Open;
rowIndex := 0;
First;
while not Eof do
begin
Inc(rowIndex);
if cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = null then
Exit;
if cxGrid1DBTableView1.ViewData.Records[rowIndex].Values[0] = '1' then
begin
Edit;
//t3表修改有效期,t4表插入一條記錄
if FieldByName('Expiry').AsString = '' then
FieldByName('Expiry').AsDateTime := Now;
sDate := FieldByName('Expiry').AsString;
FieldByName('Expiry').AsDateTime := IncMonth(FieldByName('Expiry').AsDateTime,StrToInt(edtTemp.Text));
q.SQL.Add(' insert into t4_fee(mID,DateTime,FeeType,ExtendStart,ExtendEnd,FeeIndeed,FeeShould,Operator) '+
'values('+FieldByName('mid').AsString+',getdate(),3,cast('+sDate+' as datetime)'+
',cast('+FieldByName('Expiry').AsString+' as datetime),'+eFeeTotal.Text+','+eFeeTotal.Text+','''+sName+''')');
q.ExecSQL;
end;
Next;
end;
Edit;
UpdateBatch(arAll);
q.Destroy;
end;
end;
uj5u.com熱心網友回復:
http://image.baidu.com/detail/newindex?col=&tag=&pn=0&pid=35513963359&aid=401012732&user_id=1100643875&setid=-1&sort=0&newsPn=&star=&fr=&from=2
因為group by后,group by的列也會當成一行,需要跳過去
uj5u.com熱心網友回復:
或者說cxgrid中的groupbyBox 中的列下拉時的事件轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/66162.html
標籤:數據庫相關
上一篇:如何在同一個圖表中顯現多個曲線
