打开数据库
Public Sub OpenOraDB()
On Error GoTo ToExit
OraDB_Open = False
Set OraDB = New ADODB.Connection
OraConstr = "Provider=OraOLEDB.Oracle.1Password=" & 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
一般情况下需要安装Oracle的客户端,或者ODAC,使用ODAC的话在部署的时候就不需要在机器上安装Oracle客户端了,如果使用Oracle客户端的话,在部署的时候在部署的机器上也需要安装客户端,程序初始化一个OracleConnection ,然后给个数据库连接字符串,然后OracleConnection.Open()就打开数据库连接了,使用的时候执行命令OracleDataCommand,结果用OracleDataReader欢迎分享,转载请注明来源:内存溢出
评论列表(0条)