保存图片,文本文件,word文档等等方法都是一样的
2009-08-11 09:43
357 查看
保存图片,文本文件,word文档等等方法都是一样的
保存文章的字段使用image类型
在pb中用fileread()函数把一篇文章读到一个blob型变量中,然后使用
updateblob语句把保存文章的blob型变量存到数据库中
保存image类型的变量要注意两点
1.autocommit属性要设者为true (sqlca.autocommit=true )
2.保存image型数据的表中一定要有主键,即表中要现有记录存在,而且该条记录
是唯一的,别且拥有主键。
一个保存图片的例子:
integer li_fh, li_ret, li_value
blob blob_reader_pic,blob_temp
string ls_pathname,ls_iccard_id, ls_no
string docname, named, ls_path
long ll_length,ll_size, ll_i, ll_rowcount,ll_row
long ll_len_docname, ll_len_named
sqlca.autocommit = true
li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
if li_value <> 1 then return
ll_len_docname = len(docname)
ll_len_named = len(named)
ls_path = left(docname, ll_len_docname - ll_len_named)
ll_rowcount = dw_2.rowcount()
for ll_row=1 to ll_rowcount
sle_1.text=string(ll_row)+"/"+string(ll_rowcount)
ls_no=trim(dw_2.object.vc_reader_no[ll_row])
ls_pathname= ls_path +ls_no+ ".jpg"
ll_length=filelength(ls_pathname) //检查图片是否大于32765,因为fileread一次只能读32765
if ll_length>0 then //文件存在
if ll_length<32765 then //如果小于32765,就可以马上读出来
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 and not isnull(li_fh) then
FileRead(li_fh, blob_reader_pic)
FileClose(li_fh)
end if
else //当文件大于32765时
ll_size=ll_length/32765+1 //计算出fileread要花几次读出
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 then
for ll_i=1 to ll_size
FileRead(li_fh, blob_temp) //每次读出32765字节
blob_reader_pic=blob_reader_pic+blob_temp //将读出的内容累加到另一个二进制文件中
next
FileClose(li_fh)
else
messagebox('提示','错误')
return
end if
end if
ls_iccard_id=dw_2.object.vc_iccard_id[ll_row]
Updateblob readers
Set blb_photo=:blob_reader_pic
Where vc_iccard_id =:ls_iccard_id;
if sqlca.sqlcode = 0 then
commit;
else
MessageBox("提示","更新照片出错")
Rollback;
END IF
blob_reader_pic = blob("")
else
MessageBox("提示","文件<"+ls_pathname+">不存在!")
end if
next
你使用的时候只需把
li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
中'jpg'改为你要保存的文章的扩展名即可,
word文档改为:
li_value = GetFileOpenName("读取word文档",docname, named, "doc","*.doc,*.doc,")
把sql语句中的表名和字段名改为你的,适当做一下修改就可以用了
保存文章的字段使用image类型
在pb中用fileread()函数把一篇文章读到一个blob型变量中,然后使用
updateblob语句把保存文章的blob型变量存到数据库中
保存image类型的变量要注意两点
1.autocommit属性要设者为true (sqlca.autocommit=true )
2.保存image型数据的表中一定要有主键,即表中要现有记录存在,而且该条记录
是唯一的,别且拥有主键。
一个保存图片的例子:
integer li_fh, li_ret, li_value
blob blob_reader_pic,blob_temp
string ls_pathname,ls_iccard_id, ls_no
string docname, named, ls_path
long ll_length,ll_size, ll_i, ll_rowcount,ll_row
long ll_len_docname, ll_len_named
sqlca.autocommit = true
li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
if li_value <> 1 then return
ll_len_docname = len(docname)
ll_len_named = len(named)
ls_path = left(docname, ll_len_docname - ll_len_named)
ll_rowcount = dw_2.rowcount()
for ll_row=1 to ll_rowcount
sle_1.text=string(ll_row)+"/"+string(ll_rowcount)
ls_no=trim(dw_2.object.vc_reader_no[ll_row])
ls_pathname= ls_path +ls_no+ ".jpg"
ll_length=filelength(ls_pathname) //检查图片是否大于32765,因为fileread一次只能读32765
if ll_length>0 then //文件存在
if ll_length<32765 then //如果小于32765,就可以马上读出来
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 and not isnull(li_fh) then
FileRead(li_fh, blob_reader_pic)
FileClose(li_fh)
end if
else //当文件大于32765时
ll_size=ll_length/32765+1 //计算出fileread要花几次读出
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 then
for ll_i=1 to ll_size
FileRead(li_fh, blob_temp) //每次读出32765字节
blob_reader_pic=blob_reader_pic+blob_temp //将读出的内容累加到另一个二进制文件中
next
FileClose(li_fh)
else
messagebox('提示','错误')
return
end if
end if
ls_iccard_id=dw_2.object.vc_iccard_id[ll_row]
Updateblob readers
Set blb_photo=:blob_reader_pic
Where vc_iccard_id =:ls_iccard_id;
if sqlca.sqlcode = 0 then
commit;
else
MessageBox("提示","更新照片出错")
Rollback;
END IF
blob_reader_pic = blob("")
else
MessageBox("提示","文件<"+ls_pathname+">不存在!")
end if
next
你使用的时候只需把
li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
中'jpg'改为你要保存的文章的扩展名即可,
word文档改为:
li_value = GetFileOpenName("读取word文档",docname, named, "doc","*.doc,*.doc,")
把sql语句中的表名和字段名改为你的,适当做一下修改就可以用了
相关文章推荐
- 两篇word文档行间距设置的一样但是显示的不一样的解决方法
- word文档自动保存方法
- [zz]Word 2007文档中图片不显示或对象不显示的解决方法
- 上传自己写的cacti文档,由于都是图片,自己博客保存一份记录
- 使用Python通过win32 COM实现Word文档的写入与保存方法
- 写论文时,Word文档修改保存后,文件越来越大的解决方法
- Word文档中同一行放置两个定义样式图片的方法
- 将文本文件的内容或者文字保存成图片的方法分享
- PHP导出word文档的简单实现方法(可导出图片)
- 将文本文件的内容或者文字保存成图片的方法分享
- Word中截取部分内容并保存为jpg图片的方法
- poi操作word文档,以07版本为参考,将word文档中图片替换为文本(替换文本也一样),读图片可选文字内容
- word或者pdf文件全部保存为图片的方法
- WORD 文档中的图片另存为 .jpg 格式图片方法
- Word文档中同一行放置两个图片且标题在同一行的方法
- C#设置Word文档背景的三种方法(纯色/渐变/图片背景)
- 合成图片的两种方法,思路都是一样的
- 将扫描图片转换成word文档用什么方法
- asp.net下用Aspose.Words for .NET动态生成word文档中的图片或水印的方法
- C# FileUpload上传视频、图片、文档,分别保存在不同的文件夹中以及下载文件的方法