You could do it this way:
First, you need to install Oracle Client software and make sure you are able to connect to the database (test the connection from SQL*Plus)
Then the VB code is pretty simple. This is an example using ADO:
Dim C As New ADODB.Connection
Dim Rec As New ADODB.Recordset
Dim SQL As String
'Open the connection
C.Open "Driver={Microsoft ODBC for Oracle};Server=your_database_alias; Uid=your_username;Pwd=your_password;"
'Sql command
SQL = "SELECT * FROM your_table where "
'Open the recordset
Rec.Open SQL, C, adOpenForwardOnly, adLockReadOnly
'Process the records
Do Until Rec.EOF
'do something
Loop
Rec.Close
Set Rec = Nothing
C.Close
(your_database_alias is an entry in your tnsnames.ora file and its some times the same as the service name and some times not so be careful to choose the alias not service name)
OR TRY THESE
CONNECTING TO A DATABASE IN VB USING A FUNCTION
Should be written in the module
Public Function Cons() As Connection
Set con = New Connection
With con
.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\gadget\Documents\Sql.mdb;Persist Security Info=False”
.Open
Set Cons = con
End With
Connection to a computer on the network
‘Conns.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\192.168.168.3\Users\Public\Documents\Database1.mdb;Persist Security
Info=False”
Conns.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=”
& App.Path & “\” & “KisumuPolyTTable.mdb;Persist Security Info=True;
jet OLEDB:Database Password=COMPUTER” ‘jet OLEDB:Database
Password=computer
End Function
Should be written in the module
Public Function OpenRecs(Sql As String) As Recordset
Set rst = New Recordset
With rst
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.ActiveConnection = Cons
.Source = Sql
.Open
End With
Set OpenRecs = rst
Exit Function
End Function
Centring a Form
Should be written in the module
Public Sub center(frm As Form)
With frm
.Top = ((Screen.Height / 2) – .Height / 2) – 1000
.Left = ((Screen.Width / 2) – .Width / 2) – 10
End With
End Sub
Sample Form
Private Sub Form_Load()
Center Me
With OpenRecs(“Select * from trial2”)
Text1.Text = !Name
Text2.Text = !Course
End With
End Sub
Mysql server connection module
Option Explicit
Public con As ADODB.Connection
Public rstStudent As ADODB.Recordset
Public username As String
Public pass As String
Public serverIp As String
Public db As String
Public sql As String
Public Function connectMysql(username As String, pass As String, serverIp As
String, db As String, conn As ADODB.Connection, rs As ADODB.Recordset)
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.CursorLocation = adUseClient
conn.ConnectionString = “DRIVER={MYSQL ODBC 5.1 driver}; SERVER=” &
serverIp & “; UID=” & username & “; PWD=” & pass & “; DATABASE=” & db & “;
OPTION=” & 1 + 2 + 8 + 32 + 2048 + 163841 & “”
conn.Open
End Function
************IGNORE THESE CODES ***********
Calling the connection Function from the FORM
serverIp = “127.0.0.1” ‘LocalHost IP Address
Call connectMysql(“root”, “Sylvia”, serverIp, “Admission”, con, rstStudent)
sql = “select * from PersonalDetail”
rstStudent.Open sql, con
Call JazaForm
***********************************8
Discuss This Question: 11  Replies
C.Open "Driver={Microsoft ODBC for Oracle};Server=omniqa_loc;Uid=bw3;Pwd=bw3data;"
In this part (when I run it), the message error is this: Compile error: Invalid outside procedure Also, this part of:"Driver={Microsoft ODBC for Oracle};Server=omniqa_loc;Uid=bw3;Pwd=bw3data;"
was highlighted in the color blue.