Hi
I'm doing simple connection to MS SQL and want to get count and display into excel:
How to display into Range("K3") count number?
I'm doing simple connection to MS SQL and want to get count and display into excel:
Code:
Sub test()
Dim conn As ADODB.Connection
Dim rcrds As ADODB.Recordset
Dim iRowNo, i As Long
Dim id, name, value As String
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
Dim login,passwd,host,dbname As String
login = ""
passwd = ""
host = ""
dbname = ""
Set conn = New ADODB.Connection
With conn
.ConnectionString = "driver={sql server};Server=" + host + _
";Database=" + dbname + _
";User ID=" + login + _
";Password=" + passwd + _
";Trusted_Connection=False;"
.Open
End With
Dim SQLstr As String
SQLstr = "SELECT count(*) FROM table1"
'Set rcrds = conn.Execute(SQLstr)
ws.Range("K3").Vaue = 'how to display here count number????
rcrds.Close
conn.Close
Set rcrds = Nothing
End Sub
How to display into Range("K3") count number?
Last edited: