Status
Not open for further replies.

saurabh.sauron

Ambassador of Buzz
I am facing problems in connecting VB To Oracle. Here is the code that i have used

Code:
Public Sub Conn()
Dim cn As New ADODB.Connection
Dim constr As String
Set cn = New ADODB.Connection
constr = "Provider=MSDAORA.1;user id=scott;password=tiger"
cn.Open constr
End Sub

Code:
Dim rs As New ADODB.Recordset
Dim sqlstr As String

Private Sub Command1_Click()
Call Module1.Conn
rs.CursorLocation = adUseClient
strsql = "Select * from users;"
rs.Open strsql, cn, adOpenDynamic, adLockOptimistic, adCmdText
If cn.State = adStateOpen Then
MsgBox "Open"
Else: MsgBox "Closed"
End If
End Sub

The Error:
Run Time Error 3001.
Arguments are of wrong type, unacceptable range or are in conflict with one another.

pls help
thnx
 
J

javed4shab

Guest
Hi Boss,
use this code instead, I've designed this code, This works best on any platform.


Dim con as new adodb.connection
dim rs as new adodb.recordset
Private sub form_load()
set con = new adodb.connection
with con
.connectionstring = "Provider= MSDAORA; User id=scott; password=tiger"
.connectiontimeout = 5
.cursor location = aduseclient
.open
end with
end sub


Javed Khan :wink:
 
J

javed4shab

Guest
Boss,

As I've already informed, Just use the Code I've Provided, it will work best for you.

Apart from this if you wish to do code to retrieve data just use:

Prrivate Sub cmdok_click()
set rs = new adodb.recordset
rs.open "select * from emp", con, adlockoptimistic, adopendynamic, adcmdtext
set datagrid1.datasource = rs.datasource

end sub

Just use "set datagrid1.datasource = rs.datasource" after every update to update the data grid.

also remember, recordset and connection variables, ie rs and con should be declared on module level.

to get data from any text box just type:

rs!empno = text1.text

Enjoy!

Javed Khan;-)
 

abhijeet.k1810

Right off the assembly line
The best way to handle Oracle and VB Database Connection is to Use ADODC and not ADODB if you have to use ADODB then copy and paste the ADODC code that is automatically generated by VB (incase your assignment reques it)
 
Status
Not open for further replies.
Top Bottom