中华网通行证
用户名 密码

VC/VB 进行图像数据存储数据库心得(2)
中华网科技 http://tech.china.com 2005-06-22 11:55:28
进入BBS】【进入聊天室】【 推荐给朋友 】【浏览字号: 】【关闭窗口

  
pRs->Close();
pConnection->Close();
}
catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
CString sError;
sError.Format("Source : %s n Description : %sn",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
AfxMessageBox(sError);
}


三、VB把文件存入数据库IMAGE字段
Sub savepic(FileName As String, IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER"
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call FileToBlob(rs.Fields("Image"), FileName, FileLen(FileName))
rs.UpdateBatch adAffectCurrent
End Sub

Private Sub FileToBlob(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn‘t support the GetChunk method."
End If
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = LOF(fnum)
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get #1, , tmp
fld.AppendChunk tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub


四、VB把文件从IMAGE字段中读到文件中
Sub loadpic(IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER"
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call BlobToFile(rs.Fields("Image"), "c:windowstemptmp.bmp", rs.Fields("Image").ActualSize)
End Sub

Private Sub BlobToFile(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn‘t support the GetChunk method."
End If
If Dir$(FileName) <> "" Then Kill FileName
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = fld.ActualSize
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
tmp = fld.GetChunk(bytes)
Put #fnum, , tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub

首页 上页 | 1 | 2 | 下页 尾页  共 2

50款最具性价比数码相机/MP3推荐!
作者:csdn/mynote 来源: 

发表言论:
笔  名:
查看评论
﹣相关报道

﹣精彩回顾
·揭秘越南姑娘的“性契约”(组图)
·中国研制成功银河麒麟操作系统
·近处偷拍野狮性爱 野草丛中见柔情(图)
·难得一见“水下分娩”全程跟拍(组图)
·古代性器具及性惩罚工具(组图)
·揭密中外历史上乱伦的名人们(组图)
·探秘世界各地诡异的干尸新娘(组图)
·隋唐两个王朝的九大著名"绿帽子"(组图)
·另类的惨烈:螳螂血战壁虎谁更凶猛(图)
·一分钟平静死去 注射死刑全过程(图)

进入BBS】【进入聊天室】【 推荐给朋友 】【浏览字号: 】【关闭窗口

潮流·时尚
·市场上的天价手机全搜罗
·一周降幅最大手机导购
·FM调频收音功能手机选购
·索尼爱立信三新机曝光
·诺基亚N73音乐版精品赏
·热门便携笔记本搜索导购
·近期最新上市机型大盘点
·矩阵Matrix鼠标垫细评测
·19寸20寸22寸液晶该买谁
·近期几款热卖MP3大推荐
·四大即将退市经典MP3选购
·06年最火七大DC缺点曝光
·六百万像素超值机型推荐
·诺基亚推出随身小音箱
·LG直板巧克力KG99评测
·MOTO新机即将国内上市
·超低价蓝牙手机导购
·130万像素一样拍出好照片
·诺基亚两款蓝牙耳机新品
·索爱纯美折叠机Z558评测

软件下载
·豪杰大眼睛 V2.5
·Foxmail V6.5
·天网防火墙Athena
·极品五笔 V6.8
·PPS网络电视
·超级兔子魔法设置
中华网搜索
站内搜索
全网搜索




热门搜索
耳机 印刷 手机 拖鞋
减速机 钟表 成人用品
减肥 枸杞 T恤 升降机
心理 健康 彩票 招聘
礼品 旅游 猎头 培训

产品服务
·机会!机会不容错过
·中华商机,搜索创新
·准确快捷,搜你所搜
·¥来¥往,尽在中华邮
·中华搜索,贴心搜索




科技频道主编信箱