This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub run() | |
Dim conn As ADODB.Connection | |
Dim rs As ADODB.Recordset | |
Dim sqlStr As String | |
Dim dbFilePath As String | |
Dim dbName As String | |
dbName = "DbInjectorsCatalog" | |
dbFilePath = "C:\Users\marcinchyl\Desktop\Marcin2\Projects\InjectorsCatalog\Admin\DbInjectorsCatalog.mdf" | |
connStr = "Driver={SQL Server native Client 11.0};Server=(LocalDB)\v11.0;AttachDBFileName=" & dbFilePath & ";Database=" & dbName & ";Trusted_Connection=Yes" | |
sqlStr = "Select * from Injectors" | |
Set conn = New ADODB.Connection | |
conn.ConnectionString = connStr | |
conn.Open | |
Set rs = conn.Execute(sqlStr) | |
Do While Not rs.EOF | |
Debug.Print rs!Number | |
rs.MoveNext | |
Loop | |
rs.Close | |
Set rs = Nothing | |
End Sub |
how we will do if we want to amke this connection global and use that object in other subs as well
ReplyDeleteSorry for such a late answer
DeleteI think we should do..
Could you please let me know the software installation required to support this driver?
ReplyDeleteSorry for such a late answer
DeleteI do not remember but you need to add one or two references to dlls in VBA editor