我連續新增數筆資料時才會出現錯誤,不解? |
答題得分者是:hagar
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
huangeider
高階會員 發表:288 回覆:492 積分:231 註冊:2003-02-26 發送簡訊給我 |
以下是我的部份程式碼,顯示時為什麼變成'-1',但是資料是有記錄的,請各位大大幫幫我,謝謝!!
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var xxx : string; begin xxx := IntTOstr(query1.RecNo); Label11.Caption :=xxx; end;<> 經小弟測試以上程式並無錯誤 必須再> 「堅持」從洗馬桶做起 |
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
hi, huangeider,我把程式碼po上,請教為什麼會這樣呢?
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, DBTables, StdCtrls, DBCtrls, Mask, Buttons, Grids; type TForm1 = class(TForm) Database1: TDatabase; UpdateSQL1: TUpdateSQL; BitBtnAppend: TBitBtn; BitBtnModify: TBitBtn; BitBtnDelete: TBitBtn; BitBtnYes: TBitBtn; BitBtnCancel: TBitBtn; BitBtnQuit: TBitBtn; BitBtnprior: TBitBtn; bitbtnNext: TBitBtn; Query1: TQuery; Query1REC_NO: TIntegerField; Query1ORDER_NO: TStringField; Query1GRADE: TStringField; Query1BATCH: TStringField; Query1VOLUME: TStringField; Query1DATE_1: TDateTimeField; Query1DATE_2: TDateTimeField; Query1DATE_3: TDateTimeField; Query1DATE_4: TDateTimeField; Query1ISCHANGE: TBooleanField; Query1SCRIP: TMemoField; Label1: TLabel; DBEdit1: TDBEdit; DataSource1: TDataSource; Label2: TLabel; DBEdit2: TDBEdit; Label3: TLabel; DBEdit3: TDBEdit; Label4: TLabel; DBEdit4: TDBEdit; Label5: TLabel; DBEdit5: TDBEdit; Label6: TLabel; DBEdit6: TDBEdit; Label7: TLabel; DBEdit7: TDBEdit; Label8: TLabel; DBEdit8: TDBEdit; Label9: TLabel; DBEdit9: TDBEdit; DBCheckBox1: TDBCheckBox; Label10: TLabel; DBMemo1: TDBMemo; Label11: TLabel; Label12: TLabel; procedure FormActivate(Sender: TObject); procedure BitBtnQuitClick(Sender: TObject); procedure BitBtnYesClick(Sender: TObject); procedure BitBtnAppendClick(Sender: TObject); procedure BitBtnCancelClick(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure BitBtnpriorClick(Sender: TObject); procedure BitBtnModifyClick(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; emp_no : string; implementation {$R *.dfm} procedure TForm1.FormActivate(Sender: TObject); begin UpdateSql1.InsertSQL.Clear; UpdateSql1.InsertSQL.Add('INSERT INTO G_DATA1 '); UpdateSql1.InsertSQL.Add(' ( ORDER_NO, '); UpdateSql1.InsertSQL.Add(' GRADE , '); UpdateSql1.InsertSQL.Add(' BATCH , '); UpdateSql1.InsertSQL.Add(' VOLUME, '); UpdateSql1.InsertSQL.Add(' DATE_1, '); UpdateSql1.InsertSQL.Add(' DATE_2, '); UpdateSql1.InsertSQL.Add(' DATE_3, '); UpdateSql1.InsertSQL.Add(' DATE_4, '); UpdateSql1.InsertSQL.Add(' ISCHANGE, '); UpdateSql1.InsertSQL.Add(' SCRIP )'); UpdateSql1.InsertSQL.Add(' VALUES '); UpdateSql1.InsertSQL.Add(' (:ORDER_NO,:GRADE,:BATCH,:VOLUME, '); UpdateSql1.InsertSQL.Add(' :DATE_1,:DATE_2,:DATE_3,:DATE_4, '); UpdateSql1.InsertSQL.Add(' :ISCHANGE,:SCRIP ) '); UpdateSql1.ModifySQL.Clear; UpdateSql1.ModifySQL.Add('UPDATE G_DATA1 '); UpdateSql1.ModifySQL.Add('SET '); UpdateSql1.ModifySQL.Add('ORDER_NO = :ORDER_NO,'); UpdateSql1.ModifySQL.Add('GRADE = :GRADE ,'); UpdateSql1.ModifySQL.Add('BATCH = :BATCH ,'); UpdateSql1.ModifySQL.Add('VOLUME = :VOLUME ,'); UpdateSql1.ModifySQL.Add('DATE_1 = :DATE_1 ,'); UpdateSql1.ModifySQL.Add('DATE_2 = :DATE_2 ,'); UpdateSql1.ModifySQL.Add('DATE_3 = :DATE_3 ,'); UpdateSql1.ModifySQL.Add('DATE_4 = :DATE_4 ,'); UpdateSql1.ModifySQL.Add('SCRIP = :SCRIP '); UpdateSql1.ModifySQL.Add('WHERE ORDER_NO = :OLD_ORDER_NO'); UpdateSQL1.DeleteSQL.Clear; UpdateSql1.DeleteSQL.Add('DELETE FROM G_DATA1 '); UpdateSql1.DeleteSQL.Add('WHERE ORDER_NO = :OLD_ORDER_NO'); Query1.CachedUpdates := true; Query1.UpdateObject := UpdateSql1; Query1.SQL.Clear; Query1.SQL.Add('SELECT * FROM G_DATA1'); Query1.Close; Query1.Open; end; procedure TForm1.BitBtnQuitClick(Sender: TObject); begin DataBase1.Close; Query1.SQL.Clear; close; end; procedure TForm1.BitBtnYesClick(Sender: TObject); begin Try DataBase1 .StartTransaction; Query1 .ApplyUpdates; Query1 .CommitUpdates; DataBase1 .Commit; Except DataBase1.Rollback; Query1.CancelUpdates; ShowMessage('存檔失敗 '); end; end; procedure TForm1.BitBtnAppendClick(Sender: TObject); begin Query1.Append; Query1Date_1.Value := date; Query1Date_2.Value := date; Query1Date_3.Value := date; Query1Date_4.Value := date; Query1ischange.Value:= False; Emp_No := Query1.FieldByName('ORDER_NO').AsString; Dbedit2.SetFocus; end; procedure TForm1.BitBtnCancelClick(Sender: TObject); begin Query1.Cancel; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin Query1.Next; end; procedure TForm1.BitBtnpriorClick(Sender: TObject); begin Query1.Prior; end; procedure TForm1.BitBtnModifyClick(Sender: TObject); begin Query1.Edit; DBedit2.SetFocus; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var xxx : string; begin xxx := IntTOstr(query1.RecNo); Label11.Caption :=xxx; end; procedure TForm1.FormCreate(Sender: TObject); begin end; end. |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
cashxin2002
版主 發表:231 回覆:2555 積分:1937 註冊:2003-03-28 發送簡訊給我 |
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
delphi help:
Use RecordCount with care, because record counting can be a costly operation, especially for SQL queries that return large result sets. Generally, an application should only use RecordCount with Paradox and dBASE tables.
另一方式, 用 Select Count(*) From TableName 取得 ---
Everything I say is a lie.
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
|
leo2568
中階會員 發表:54 回覆:124 積分:70 註冊:2003-09-21 發送簡訊給我 |
|
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |