vb数据库连接字符串
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
*************************************************************************
**
** 使用adodb.stream 保存/读取文件到数据库
** 引用microsoft activex data objects 2.5 library 及以上版本
**
** ----- 数据库连接字符串模板---------------------------------------
** access数据库
** iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
** ";data source=数据库名"
**
** sql数据库
** iconcstr = "provider=sqloledb.1;persist security info=true;" & _
** "user id=用户名;password=密码;initial catalog=数据库
名;data source=sql服务器名"
**
*************************************************************************
保存文件到数据库中
sub s_savefile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconcstr as string
数据库连接字符串
iconcstr = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=f:/my documents/客户资料1.mdb"
读取文件到内容
set istm = new adodb.stream
with istm
.type = adtypebinary 二进制模式
.open
.loadfromfile "c:/test.doc"
end with
打开保存文件的表
set ire = new adodb.recordset
with ire
.open "表", iconc, adopenkeyset, adlockoptimistic
.addnew 新增一条记录
.fields("保存文件内容的字段") = istm.read
.update
end with
完成后关闭对象
ire.close
istm.close
end sub
从数据库中读取数据,保存成文件
sub s_readfile()
dim istm as adodb.stream
dim ire as adodb.recordset
dim iconc as string
数据库连接字符串
iconc = "provider=microsoft.jet.oledb.4.0;persist security info=false" & _
";data source=//xz/c$/inetpub/zj/zj/zj.mdb"
打开表
set ire = new adodb.recordset
ire.open "tb_img", iconc, adopenkeyset, adlockreadonly ire.filter = "id=64"
保存到文件
set istm = new adodb.stream
with istm
.mode = admodereadwrite
.type = adtypebinary
.open
.write ire("img")
.savetofile "c:/test.doc"
end with
关闭对象
ire.close
istm.close
end sub
dim cn as new adodb.connection
dim rs as new adodb.recordset
dim stm as adodb.stream
private sub savepicturetodb(cn as adodb.connection)
将bmp图片存入数据库
on error goto eh
set stm = new adodb.stream
rs.open "select imagepath,imagevalue from tbl_image", cn, adope nkeyset, adlockoptimistic
commondialog1.showopen
text1.text = commondialog1.filename
with stm
.type = adtypebinary
.open
.loadfromfile commondialog1.filename
end with
with rs
.addnew
.fields("imagepath") = text1.text
.fields("imagevalue") = stm.read
.update
end with