任意文件格式存入sqlserver2000中的image字段中大多时侯能存取,有时出现文件损坏请高手帮我 ( 积分: 100 )

  • 主题发起人 主题发起人 阻击手
  • 开始时间 开始时间

阻击手

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure&nbsp;Tfrm_savemb.b_saveClick(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;stream:TADOBlobStream;<br>&nbsp;&nbsp;stream1:TFileStream;<br>&nbsp;&nbsp;filename:string;<br>begin<br>&nbsp;&nbsp;if&nbsp;copy(pub_mbdldm&nbsp;,1,2)='12'&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;filename:=GetCurrentDir+'/'+'emrtemp.emk';<br>&nbsp;&nbsp;&nbsp;&nbsp;frm_mbbj.EMRPad301.FileSaveAs(FileName,2,0);<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;filename:=GetCurrentDir+'/'+'emrtemp.emr';<br>&nbsp;&nbsp;&nbsp;&nbsp;frm_mbbj.EMRPad301.FileSaveAs(FileName,1,0);<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;qry_mbmx.Close;<br>&nbsp;&nbsp;qry_mbmx.Parameters.ParamByName('mbid').Value:=pub_mbid;<br>&nbsp;&nbsp;qry_mbmx.Open;<br>&nbsp;&nbsp;if&nbsp;editmode='add'&nbsp;then&nbsp;qry_mbmx.Append;<br>&nbsp;&nbsp;if&nbsp;editmode='edit'&nbsp;then&nbsp;qry_mbmx.edit;<br>&nbsp;&nbsp;qry_mbmx['dm']:=pub_mbdldm;<br>&nbsp;&nbsp;qry_mbmx['mbmc']:=pub_mbmc;<br>&nbsp;&nbsp;qry_mbmx['mbsx']:=pub_mbsx;<br>&nbsp;&nbsp;qry_mbmx['zyksgs']:=pub_mbks;<br>&nbsp;&nbsp;qry_mbmx['mbczy']:=pub_czyxm;<br>&nbsp;&nbsp;if&nbsp;copy(pub_mbdldm&nbsp;,1,2)='12'&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qry_mbmx['wjmc']:=pub_mbmc+'.emk'<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qry_mbmx['wjmc']:=pub_mbmc+'.emt';<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream1:=TFileStream.Create(FileName,fmOpenRead);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream1.Position:=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream:=TADOBlobStream.Create(qry_mbmx.FieldByName('mbwj')as&nbsp;&nbsp;&nbsp;&nbsp;TBlobField,bmRead);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.Position:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.CopyFrom(stream1,&nbsp;stream1.Size);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qry_mbmx.Post;<br>&nbsp;&nbsp;Finally<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.Free;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream1.Free;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;close;<br>end;
 
image字段可以存取任何数据类型,不过它保存的是二进制而已。<br>你要保存文件,直接用TBlobField读存文件就可以了,读取文件取数据库方法如下:<br>如下:<br>TBlobField(qry_mbmx.FieldByName('mbwj')).LoadFromFile(lsFileName);
 
ado,没法使用TBlobField
 
你的问题在&nbsp;http://xieyunc.blog.163.com/&nbsp;上也有,博主也遇到过此问题。
 
后退
顶部