#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default ADODB

The following code cycles through the recordset OK, but the RS.RecordCount
is allways = -1. I Need to be able to run a query from which I can tell if a
record exists, if I cant determine the record count I dont know how to
procede

Any help is appreciated


Sub Northwind()

Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rec As New ADODB.Record

Dim sqlString As String
sqlString = "SELECT * FROM CUSTOMERS"

con.ConnectionString = "Driver={SQL
Server};Server=MYSERVER;Database=NORTHWIND;Uid=sa; Pwd=password;"
con.Open
cmd.ActiveConnection = con
cmd.CommandText = sqlString
cmd.CommandType = adCmdText

Set rs = cmd.Execute(sqlString)

rs.MoveFirst
Do While Not rs.EOF
Debug.Print rs.Fields(0)
rs.MoveNext
Loop

con.Close
Set con = Nothing
Set cmd = Nothing
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default ADODB

Thanks Robin,

This seems to have done the trick.


Regards


"Robin Hammond" wrote in
message ...
Try this syntax which sets your cursor type:

rs.Open sqlString, con, adOpenStatic, adLockBatchOptimistic, adCmdText

--
Robin Hammond
www.enhanceddatasystems.com


"Mr Struggler" <lkjhlkj wrote in message
...
The following code cycles through the recordset OK, but the
RS.RecordCount is allways = -1. I Need to be able to run a query from
which I can tell if a record exists, if I cant determine the record count
I dont know how to procede

Any help is appreciated


Sub Northwind()

Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rec As New ADODB.Record

Dim sqlString As String
sqlString = "SELECT * FROM CUSTOMERS"

con.ConnectionString = "Driver={SQL
Server};Server=MYSERVER;Database=NORTHWIND;Uid=sa; Pwd=password;"
con.Open
cmd.ActiveConnection = con
cmd.CommandText = sqlString
cmd.CommandType = adCmdText

Set rs = cmd.Execute(sqlString)

rs.MoveFirst
Do While Not rs.EOF
Debug.Print rs.Fields(0)
rs.MoveNext
Loop

con.Close
Set con = Nothing
Set cmd = Nothing
End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB Timeout MChrist Excel Programming 1 December 8th 05 05:30 PM
ADODB SQL help Eric Excel Programming 1 August 4th 05 04:48 PM
ADODB Question luvgreen Excel Programming 8 November 15th 04 11:46 AM
Problems with ADODB Eric Wescott Excel Programming 6 October 20th 04 03:50 PM
ADODB Richard Mogy Excel Programming 3 May 6th 04 09:14 PM


All times are GMT +1. The time now is 04:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"