首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 计算机考试 > 认证考试 > ORACLE/CIW认证 >

VB连接ORACLE数据库

2008-10-05 
'打开数据库 public sub openoradb() on error goto toexit ...
'打开数据库

public sub openoradb()
on error goto toexit
oradb_open = false
set oradb = new adodb.connection
oraconstr = "provider=oraoledb.Oracle.1;password=" & strorapwd & ";user id=" & strorauser & ";data source=" & oradbnetname & ";persist security info=false"
oradb.cursorlocation = aduseserver

oradb.open oraconstr
oradb_open = true

exit sub
toexit:
'msgbox "连接数据库服务器错误,您可以在网络正常后继续使用。",vbinformation , "错误信息"
oradb_open = false
end sub

'关闭数据库

public sub closeoradb()
if oradb_open = true then
if (oradb.state = adstateopen) then
oradb.close
set oradb = nothing
oradb_open = false
end if
end if
end sub

'打开数据集,写入数据

set orars = new adodb.recordset
orars.activeconnection = oradb
orars.cursorlocation = aduseserver
orars.locktype = adlockbatchoptimistic
strorars = "select * from " & oradbtablename
orars.open strorars, oradb, adopenstatic, adlockoptimistic
orars.addnew
orars.fields("pid") = strorapid
orars.fields("pname") = strname").value
orars.fields("psex") = strpsex
orars.update

'关闭数据集

orars.close
set orars = nothing

热点排行