Vba macro ORACLE connection

Source: Internet
Author: User

One type:

Sub test ()
'Test macro

Dim cn As ADODB. Connection
Dim rs As ADODB. Recordset
Set cn = New ADODB. Connection
Cn. Open "Provider = OraOLEDB. Oracle.1; PassWord = XXXX; Persist Security Info = True; User ID = XXXX; Data Source = XXXX; Extended Properties = PLSQLRSet = 1"
StrQuery = "select count (*) as rscount from staff"
Set rs = New ADODB. Recordset
Rs. Open strQuery, cn, adOpenStatic, adLockOptimistic
MsgBox rs ("rscount ")
End Sub

Another type:

Dim Con As New ADODB. Connection
Dim rst As New ADODB. Recordset
Dim Cmd As New ADODB. Command
Dim rsSQL As String
Dim PassId As Integer
Dim State As Integer
Dim Prm1 As New ADODB. Parameter
Dim Prm2 As New ADODB. Parameter
Con. ConnectionString = "Provider = OraOLEDB. Oracle.1; PassWord = cqboa; Persist Security Info = True; User ID = cqboa; Data Source = nsoa; Extended Properties = PLSQLRSet = 1"

Con. Open
RsSQL = "select t. aa from table t where t. No. =" & "5484"
With Cmd
. ActiveConnection = Con
. CommandType = ad1_text
. CommandText = rsSQL
Rst. CursorType = adOpenStatic
Rst. LockType = adLockReadOnly
Set rst. Source = Cmd
Rst. Open
Set PassId = rst. Fields ("no."). Value
Set State = 0
Set rst = Nothing
Set Cmd = Nothing
Con. Close

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.