Solved

VB6 with oracle

Posted on 2004-09-29
6
649 Views
Last Modified: 2010-05-18
Dear Sir

  please provide me with the simplest way to connect my vb6 form to oracle DB, table for insert, edit, delete   if there is any lib or wizard it will be better


Thank you

Eng. Omar Fayyad
0
Comment
Question by:omarmf
6 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 25 total points
ID: 12185440
omarmf,

I think the key thing is to be able to connect to the database. Once you have done this you can then use styandard SQL.


'In a module put the following line:
Public myDB As ADODB.Connection

'In a function to connect to the database:
    Set myDB = New ADODB.Connection
    With myDB
        .ConnectionString = "UID=scott;PWD=tiger;DRIVER={Microsoft ODBC for Oracle};SERVER=myTNSName;"
        .Open
    End With


'In a function to update a table on the database:

Dim MySet as ADODB.Recordset
Set MySet = New ADODB.Recordset
myDB.Execute "Update Table1 Set field1 = 'A' where field2 = #XYZ'" , , adExecuteNoRecords
0
 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 25 total points
ID: 12186654
I used to put a provider there, not sure if omit the provider will it still work?


...
.ConnectionString = "Provider=MSDASQL;DRIVER={Microsoft ODBC for ORACLE};UID=scott;PWD=tiger;Server=myTNSName"
...



Other methods using of ConnectionString for Oracle can be found at links below:

http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForOracleFromOracle
http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForOracleFromMicrosoft
http://www.connectionstrings.com

regards
0
 
LVL 3

Assisted Solution

by:sgayatri
sgayatri earned 75 total points
ID: 12188270
ryancys,
its allowed without giving provider, that is the advantage of using this ...
 
omar,
try this.
Add a command button to your code
Add Project >> references >> Activex Data Objects 2.0 library
Add Project >> references >> Activex Data Objects Recordset 2.1 library

private sub command1_click()

dim cn as new adodb.connection
dim rs as new adodb.recordset

on error goto conerr
with cn
''' substitute proper parameters for username,password,Server
.ConnectionString = "DRIVER={Microsoft ODBC for ORACLE};UID=username;PWD=password;Server=myTNSName"
.open
end with

on error goto rserr
str="select a,b from db"   '' add your select/insert/update  statement here
rs.open str1,cn,adopenkeyset
''''your data is in recordset now if it is a select statement
'''You can use it as
field1 = rs(0)
field2 = rs(1)

exit sub
conerr:
  msgbox "connection error here!"
  msgbox err.description,,err.number
  exit sub

rserr:
  msgbox "Recordset error here!"
  msgbox err.description,,err.number
 
end sub
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 50

Expert Comment

by:Ryan Chong
ID: 12188301
Thks for the info, sgayatri!
0
 

Author Comment

by:omarmf
ID: 12201244
Dear sir

I m finding toubles in logning to the oracle server

.ConnectionString = "DRIVER={Microsoft ODBC for ORACLE};UID=SCOTT;PWD=TIGER;Server=MYNDBNAM"


What to do ???
0
 

Author Comment

by:omarmf
ID: 12201357
i think the problem could be solved by adding script describing connect as sysdba
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question