- 註冊時間
- 2006-3-13
- 最後登錄
- 2024-8-25
- 在線時間
- 673 小時
- 閱讀權限
- 200
- 積分
- 417
- 帖子
- 1107
- 精華
- 0
- UID
- 2
|
範例:
- procedure Button1Click(Sender:TObject);
- var
- Query : TQuery;
- StringStream : TStringStream;
- begin
- StringStream := TStringStream.Create ('');
- Memo.Lines.SaveToStream (StringStream);
- StringStream.Position := 0;
- Query := TQuery.Create(self);
- Query.DatabaseName := Database.DatabaseName;
- with Query.SQL do
- begin
- Clear;
- Append ('INSERT INTO TEST');
- Append ('(ID,CONTENT)'); //CONTENT是一個 Image 欄位
- Append ('VALUES (:ID, :CONTENT)');
- end;
- with Query do
- begin
- ParamByName ('ID').asInteger := StrToIntDef (edtID.Text,0);
- ParamByName ('CONTENT').asBlob := StringStream.DataString; //就在這裡指定
- end;
- StringStream.Free; //用完了馬上 Free 掉
- Database.StartTransaction; //開始交易控制
- try
- Query.ExecSQL; //開始插入紀錄
- Database.Commit;
- except
- Query.Free; //如果出錯首先將 Query Free 掉
- Database.RollBack;
- raise; //重新引發例外, 以通知使用者
- end;
- Query.free;
- end;
複製代碼 |
|