I need to insert a Values to the table in SQL Server from VBA .I tried Something I mentioned below .But I couldn't able to achieve my results .please guide me to solve this .I am using Exact Conn String in my Option even though its not functioning.
- Sub To_SQL()
-
- Dim conn As ADODB.Connection
- Dim cmd As ADODB.Command
- Dim strSQL As String
-
- 'Create a new Connection object
- Set conn = New ADODB.Connection
-
- 'Set the connection string
- conn .ConnectionString = "Data Source=55.50.53.9;Initial Catalog=Management;Persist Security Info=True;User ID=licenceusr;Password=******"
-
- 'Open the Connection to the database
- conn .Open **
- conn .Execute "insert into MyTableName (firstname, lastname) values('""Dhini""','""Dhini""')"
- 'Create a new Command object
- Set cmd = New ADODB.Command
-
- End Sub()
Thanks in advance.