关于从sql2000取image字段数据的问题

cailover 2009-08-03 02:58:33
我有一个数据库,里面有个image字段存放照片的,image字段是可以为NULL的

我写了一段程序

itm.Type = adTypeBinary
itm.Open
itm.Write rs!photo
itm.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite

itm.Close
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")

这样的image非null值的可以正常显示,但是image是null值的就报错


我就又写了
If IsNull(rs!photo) = True Then
Else
itm.Type = adTypeBinary
itm.Open
itm.Write rs!photo
itm.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite

itm.Close
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")
End If

那这样的话image是null的不报错能显示了,而image是非null值的就报错“实时3001”
itm.Write rs!photo出错


哪位高手能帮帮我啊???
...全文
97 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
倒大霉的上帝 2009-08-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 vbman2003 的回复:]
select * from tb photo is not null
[/Quote]
正解
vbman2003 2009-08-03
  • 打赏
  • 举报
回复

If not IsNull(rs!photo) Then
set itm=new adodb.stream
with itm
.Type = adTypeBinary
.Open
.Write rs!photo
.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite
.Close
end with
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")
Else
Image1.Picture = LoadPicture()
End If
cailover 2009-08-03
  • 打赏
  • 举报
回复
问题解决了,居然要在if语句之前先把rs!photo赋值,然后在if语句里面对所赋值的量来判断!谢谢大家了!
vbman2003 2009-08-03
  • 打赏
  • 举报
回复
select * from tb photo is not null
vbman2003 2009-08-03
  • 打赏
  • 举报
回复
如果可以,直接在SQL语句中解决:
select * from tb photo not is null
cailover 2009-08-03
  • 打赏
  • 举报
回复
Leftie,我刚才试过了,用我原来的程序,在image非空的几个数据间切换都是可以正常显示的,不需要预先删除文件
饮水需思源 2009-08-03
  • 打赏
  • 举报
回复
If not IsNull(rs!photo) Then 
itm.Type = adTypeBinary
itm.Open
'文件已经存在,则先删除
if dir("d:\bgxvb\temp.jpg")<>"" then kill d:\bgxvb\temp.jpg
itm.Write rs!photo
itm.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite

itm.Close
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")
End If

cailover 2009-08-03
  • 打赏
  • 举报
回复
如果把“if rs!photo <> null then”换成 “IsNull(rs!photo) = flase”又是和我一开始的时候一样了
cailover 2009-08-03
  • 打赏
  • 举报
回复
jhone99,你的方法不行

报错“类型不匹配”

“if rs!photo <> null then ”这行出错
jhone99 2009-08-03
  • 打赏
  • 举报
回复
itm.Type = adTypeBinary
itm.Open

if rs!photo <> null then
itm.Write rs!photo
itm.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite

itm.Close
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")
end if
jhone99 2009-08-03
  • 打赏
  • 举报
回复
itm.Type = adTypeBinary
itm.Open

if rs!photo =null then
itm.Write rs!photo
itm.SaveToFile "d:\bgxvb\temp.jpg", adSaveCreateOverWrite

itm.Close
Set itm = Nothing
Image1.Picture = LoadPicture("d:\bgxvb\temp.jpg")
end if

饮水需思源 2009-08-03
  • 打赏
  • 举报
回复
可能是文件已经存在了,itm.Write rs!photo之前先判断文件是否存在,已存在则删除

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧