| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 774 人关注过本帖
标题:[求助]保存二进制文件错误
只看楼主 加入收藏
tlg520
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-3-17
收藏
 问题点数:0 回复次数:3 
[求助]保存二进制文件错误

Public photofpath As String Private Sub savaphoto(fld As ADODB.Field, pathfile As String) Dim bytedata() As Byte '定义数据块数组 Dim numblocks As Long '定义数据个数 Dim filelength As Long '标识文件长度 Dim leftover As Long '定义剩余字节长度 Dim sourcefile As Long '定义自由文件号 Dim blocksize As Long '定义每次读写块的大小 Dim i As Long sourcefile = FreeFile blocksize = 4096 Open pathfile For Binary As sourcefile '打开文件 filelength = LOF(sourcefile) If filelength = 0 Then Close sourcefile MsgBox pathfile & "无内容或不存在!" Else numblocks = filelength / blocksize '得到数据块的个数 leftover = filelength Mod blocksize '得到剩余字节数 fld.Value = Null ReDim bytedata(blocksize) '重新定义数据块的大小 For i = 1 To numblocks Get sourcefile, , bytedata() '读到内存中 fld.AppendChunk bytedata() '写入fld '错误  “操作在该内容不被允许????????????” Next i ReDim bytedata(leftover) Get sourcefile, , bytedata() '读到内存块 fld.AppendChunk bytedata() '写入fld Stop Close sourcefile End If End Sub

Private Sub Command1_Click() Dim comd As ADODB.Command Dim falg As Boolean Dim sql, xh, name, dp, class, tel, zy, post, addr, sex, zzmm, memo Dim born As Date Dim sd As String Dim adorst As New ADODB.Recordset Dim adofld As ADODB.Field Set comd = New ADODB.Command falg = True xh = Text1.Text: name = Text2.Text: dp = Text3.Text: sex = Combo1.Text: zzmm = Combo5.Text born = Val(Combo2.Text) & "-" & Val(Combo3.Text) & "-" & Val(Combo4.Text) post = Text6.Text: zy = Text4.Text: class = Text5.Text: addr = Text8.Text: memo = Text9.Text If Text1 = "" Then MsgBox "学号不能为空" falg = False End If If Text2 = "" Then MsgBox "姓名不能为空" falg = False End If If Text3 = "" Then MsgBox "系部不能为空" falg = False End If If Text4 = "" Then MsgBox "专业不能为空" falg = False End If If Text5 = "" Then MsgBox "班级不能为空" falg = False End If If Text6 = "" Then MsgBox "邮政编码不能为空" falg = False End If If Text8 = "" Then MsgBox "家庭住址不能为空" falg = False End If If falg = True Then sql = "insert into stucomple(学号,姓名,性别,系部,专业,班级,政治面貌,家庭住址,出生日期,邮政编码,联系电话,备注)values('" & xh & "','" & name & "','" & sex & "','" & dp & "','" & zy & "','" & class & "','" & zzmm & "','" & addr & "','" & born & "','" & post & "','" & tel & "','" & memo & "')" comd.ActiveConnection = con comd.CommandText = sql comd.Execute Set adorst = New ADODB.Recordset adorst.Source = "select photo from stucomple" adorst.Open , con, 1, 3 Set adofld = adorst.Fields(0) Call savaphoto(adofld, photofpath) adorst.Update If MsgBox("新记录已经添加,是否继续添加?", vbOKCancel, "添加记录") = vbCancel Then Set comd = Nothing Unload Me Else Text1 = "": Text2 = "": Text3 = "": Text4 = "": Text5 = "": Text6 = "": Text7 = "": Text8 = "": Text9 = "" Text1.SetFocus Combo5.Text = "党员" Combo1.Text = "男" Combo2.Text = "1975" Combo3.Text = "1" Combo4.Text = "1" End If End If End Sub 保存其它的没问题 但保存那个照片时有一点问题,,       问题在解释那里写了一下 各位帮我指点一下行吗? 谢谢!!!

搜索更多相关主题的帖子: 二进制 文件 保存 
2005-03-19 14:05
tlg520
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-3-17
收藏
得分:0 
也就是在“ fld.AppendChunk bytedata() '写入fld                              '错误  “操作在该内容不被允许????????????”
2005-03-19 14:07
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
fld是个什么类型的对象?或变量?在哪里有定义?
2005-03-19 21:44
tlg520
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-3-17
收藏
得分:0 
Private Sub savaphoto(fld As ADODB.Field, pathfile As String)是Call savaphoto(adofld, photofpath)的调用,前面定义了Dim adofld As ADODB.Field,在单击事件里已经有Set adofld = adorst.Fields(0)
2005-03-21 09:32
快速回复:[求助]保存二进制文件错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020669 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved