Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql Fetching in VB

Status
Not open for further replies.

myasin78

Programmer
Jan 26, 2004
50
US
Hello,

I am trying to fetch an oracle table using vb app.
here is my current code.
can someone tell me what i am doing wrong.

Private Sub Command1_Click()
Dim Rs1 As New ADODB.Recordset
Dim buffer As String
Dim dbConn As New ADODB.Connection
Dim strSql As String

buffer = "DSN=yamato;UID=myasin;PWD=mypasswd"
dbConn.Open buffer

strSql = "SELECT * FROM tableName"
Rs1.open strSql
With Rs1
.MoveFirst
txtoutput.Text = Rs1.Fields(1)
End With
Rs1.Close

thanks,
 
Why use the .MoveFirst method ?
Anyway, what is your problem ?
 
On the line:
Rs1.open strSql

you need to refer to the open connection:
Rs1.open strSql,dbConn

Then it will work OK.

At the end of the sub, you need to close both the connection and the recordset, then set them both to nothing:

Rs1.Close
dbConn.Close

Set Rs1 = Nothing
Set dbConn = Nothing

Be aware that the Fields collection starts with (0), instead of (1).

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top