if trim(OpenFileNameStr)='' then
begin
OpenSQL(1,nil,7);
ShowDialog('修改成功!','',mtinformation,'信息');
end;
if trim(OpenFileNameStr)<>'' then
begin
OpenSQL(1,nil,7);
MyClient:=TClientDataSet.Create(self);
MyClient.RemoteServer:=Socketconnection;
MyClient.ProviderName:=Socketconnection.AppServer.NewDataSet;
MyClient.Close;
MyClient.CommandText:='select * From TB_BD_SB_BDSBSYFAGL where JHBH='''+MyStr+'''';
MyClient.Open;
MyClient.Edit;
TBlobfield(MyClient.fieldbyname('FANR')).loadfromfile(OpenFileNameStr);
MyClient.Post;
Myclient.ApplyUpdates(0);
ShowDialog('修改成功!','',mtinformation,'信息');
SocketConnection.AppServer.DelDataSet(MyClient.ProviderName);
MyClient.Free;
这是我的源代码,OpenSQL(1,nil,7)是我自己写的执行SQL语句的函数,OpenFileNameStr是文件名,大家看的时候可以不考虑它,这一段是修改保存,因为我是多表操作,所以选择了分步存储,虽然存储和打开都成功了,但我觉得方法比较笨拙,哪位大哥能给个更好的方法。
procedure TFrmBDSB.btnOpenClick(Sender: TObject);
var
Buffer: array[0..MAX_PATH] of Char;
begin
if CDBDSB.fieldByName('FANR').AsString = '' then
begin
showdialog('没有方案内容!','',mtError);
exit;
end;
try
GetTempPath(SizeOf(Buffer) - 1, Buffer);
except
showdialog('获得临时文件路径出错!','',mtError);
exit;
end;
TBlobField(CDBDSB.fieldByName('FANR')).savetofile(string(Buffer)+'EpmTemp.doc');
try
shellexecute(application.Handle, 'open',pchar(string(Buffer)+'EpmTemp.doc'), '', nil, SW_Hide);
except
showdialog('您可能没有安装word应用程序','',mtError);
exit;
end;
end;
这是我的打开事件,看看就行了,这个不需要什么修改。