打開數據庫
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