今天是:   | 登录中心 | | 网络导航
logo 来海南旅游咨询 海南旅游 预订海南酒店 自驾租车 海南高尔夫 问路订房就请拔打海南旅游百事通  全天24小时为您守候 设为首页
加入收藏
联系站长
导航页为首页
内容页为首页
当前位置:南国风 >> IT.信息技术 >> powerbuilder-pb >> 浏览文章

blob在sql server中image类型更新数据的注意事项

作者:佚名 日期:2008年09月12日 来源:本站原创 人气:

将文件或图片存入数据库

1.要自动提交关闭,
   sqlca.autocommit = false
2。不能让image列内容为null,所以要先使用insert 或update便image列有个值
update t_membercard set photo='' where id=:l_id;

3.要记得先提交
commit;

3.使用updateblob更新blob类型数据, 一次只能更新一行
UPDATEBLOB 表名 SET image类型列 =:blob变量  WHERE id = :关键字;

4.还原自动提交
sqlca.autocommit = TRUE

例程:
////将图保存到数据库
long l_flength,l_count
int i_file,i_loops,i,i_byte
blob b_temp,b_sqlca
int i_row
long l_id
string s_pathname,s_fname


is_photoname=GetCurrentDirectory() +"\temptosave.jpg"

//----------delete the temporary
if(fileexists(is_photoname) ) then
 filedelete(is_photoname)
end if

i_row=dw_card.getrow()
if(i_row<1) then
 messagebox("","请先新增一条记录")
 return -1
end if

dw_card.accepttext()
dw_card.update()
//event ue_savecard()
l_id=dw_card.getitemnumber(i_row,"id")
if(l_id <1) or isnull(l_id) then
 messagebox("","不正确的文件")
 return -1
end if

getfileopenname("选相片文件",s_pathname,s_fname,"图片(*.jpg),*.jpg,","jpg,*.jpg,jpeg,*.jpeg,gif,*.gif")

if trim(s_pathname)="" then return -1

filecopy(s_pathname,is_photoname,true)

l_flength= FileLength(is_photoname)
if(l_flength<1) then
 messagebox("","文件不正确或扫描不成功,请重试")
 return  -1
end if

filecopy(s_pathname,is_photoname,true)


dw_card.object.p_1.fileName=is_photoname

i_file=fileopen(is_photoname, StreamMode!, Read!, LockRead!)
IF l_flength > 32765 THEN
  IF Mod(l_flength, 32765) = 0 THEN
   i_loops = l_flength/32765
  ELSE
   i_loops = (l_flength/32765) + 1
  END IF
ELSE
  i_loops = 1
END IF

FOR i = 1 to i_loops
  i_byte = FileRead(i_file, b_temp)
  b_sqlca = b_sqlca + b_temp  
NEXT
FileClose(i_file)
l_flength=len(b_sqlca)
sqlca.autocommit = false
update t_membercard set photo='' where id=:l_id;
commit;
UPDATEBLOB t_membercard SET photo =:b_sqlca WHERE id = :l_id;

//messagebox("",string(sqlca.sqlcode))
if(sqlca.sqlcode<>0) then
 messagebox("载入图时出错",sqlca.SQLErrText)
end if
commit;
sqlca.autocommit = TRUE
return 1


上一篇:没有了
email:lifat@yeah.net| QQ:_3000_99**61 T先生
  服务指南 | 著作权与商标声明 | 法律声明 | 服务条款 | 隐私声明 |


南国风网站的版权信息:保留所有权力

不良信息举报中心!
琼ICP备15001822号