Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
ADODB Timeout | Excel Programming | |||
ADODB SQL help | Excel Programming | |||
ADODB Question | Excel Programming | |||
Problems with ADODB | Excel Programming | |||
ADODB | Excel Programming |