我的一段操作程序
procedure TMainForm.BtnInsertClick(Sender: TObject);
var
MyStream:TmemoryStream;
FileName:String;
i:Integer;
begin
if OpenDialog1.Execute then
begin
Filename:=OpenDialog1.FileName;
end
else
begin
Exit;
end;
MyStream:=TMemoryStream.Create;
try
MyStream.loadfromfile(Filename);
MyStream.Seek(0,soFromBeginning);
Database1.Open;
database1.StartTransaction;
try
WITH Query1 do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO CTCS2E.D_EXECUTE VALUES
PROGNAME,:UPDATEDATE,:EXE)');
ParamByName('PROGNAME').AsString:=GetFileName(Filename);
ParamByName('UPDATEDATE').AsDateTime:=Now;
ParamByName('EXE').LoadFromStream(MyStream,ftBlob);
ExecSQL;
end;
Database1.Commit;
except
On E: EDBEngineError do
begin
Database1.Rollback;
for i := 0 to E.ErrorCount - 1 do
begin
case E.Errors
.ErrorCode of
$2601:
begin
ShowMessage('呵呵!我不允许鍵值重覆!');
end;
$0021:
begin
Showmessage('太糟糕了,系统发生故障!TMD');
end;
$270b:
begin
Showmessage('对不起,你不能破坏引用完整性!怎么样,很失望吧!');
end;
$2b05:
begin
Showmessage('太糟糕了,网络连接超时判负!TMD');
end;
$0028:
begin
Showmessage('琐定违例!');
end;
$1200:
begin
Showmessage('不能识别的SQL错误!呵呵,有事干了!');
end;
$2501:
begin
Showmessage('太糟糕了,你的内存不足!请使用N(N>=10000)兆内存');
end;
$2728:
begin
Showmessage('你所操作的表不存在!');
end;
$2801:
begin
Showmessage('记录已经被其它用户琐定!');
end;
$2a06:
begin
Showmessage('数据引擎初始化错误!');
end;
$2c01:
begin
Showmessage('网络初始化失败!');
end;
$2c07:
begin
Showmessage('呜呜..呜呜!一个我不知道的网络错误,这不可能!');
end;
$2c0d:
begin
Showmessage('是谁干的!!服务器竟然没打开!');
end;
$3e07:
begin
Showmessage('初始化失败!');
end;
$3303:
begin
//ShowMessage('服务器端错误:一般的SQL错误!');
end;
else
raise EDatabaseError.Create(E.Message);
end;//case
end;//for
end;//on EDBError
end;//try..except
finally
MyStream.Free;
end;
end;