i have connected the database which is created by sql server, and problem is i don't know how to excute sql and retrieve result from it, this code doesn't work, something wrong with recordset, what should i do? thanks a lot for any help!
Sub QueryFN()
.....
Dim X As String
Dim dealsConnection As Connection
Dim rs As Recordset
X = "ODBC;filedsn=c:\Program Files\Common Files\ODBC\Data Sources\QuantumIreland;DBQ=QuantumIreland;DSN=deals;UId=sa;PWD=sa"
Set dealsConnection = _
wrkODBC.OpenConnection("deals", , False, X)
Dim SQLStmt As String
SQLStmt = " ... "
Set rs = dealsConnection.OpenRecordset(SQLStmt, dbOpenSnapshot)
With ThisWorkbook.Sheets("Sheet1"
With .Cells(2, 1)
.CurrentRegion.Clear
numberOfRows.CopyFromRecordset (rs)
End With
End With
.....
End Sub
Sub QueryFN()
.....
Dim X As String
Dim dealsConnection As Connection
Dim rs As Recordset
X = "ODBC;filedsn=c:\Program Files\Common Files\ODBC\Data Sources\QuantumIreland;DBQ=QuantumIreland;DSN=deals;UId=sa;PWD=sa"
Set dealsConnection = _
wrkODBC.OpenConnection("deals", , False, X)
Dim SQLStmt As String
SQLStmt = " ... "
Set rs = dealsConnection.OpenRecordset(SQLStmt, dbOpenSnapshot)
With ThisWorkbook.Sheets("Sheet1"
With .Cells(2, 1)
.CurrentRegion.Clear
numberOfRows.CopyFromRecordset (rs)
End With
End With
.....
End Sub