LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Using ADO with INSERT query

I'm trying to do this in VBA:

Dim cn As New ADODB.Connection
Dim sql As String

cn.Open "Driver={SQL
Server};Server=servername;Database=dbname;Uid=user id;Pwd=password"

sql = "INSERT INTO table_name " & _
"(field_1,field_2,field_3,field_4) " & _
"Values ('value1','value2','value3','value4')"
cn.Execute sql

I get an automation error with the Execute method. However, if I run
the query from Query Analyzer it works. So, I'm pretty sure the
problem is either I'm not setting up the sql string properly to use
with cn.Execute, or I'm using the wrong ADO objects/methods.

How do I do this correctly?

tod

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ADO with INSERT query todtown Excel Programming 0 August 18th 07 01:48 AM
Using ADO with INSERT query todtown Excel Programming 0 August 18th 07 01:48 AM
Web Query Error 1004 - Cannot insert columns... Steach91[_3_] Excel Programming 1 January 8th 06 02:10 PM
Range.Insert query [email protected] Excel Programming 1 September 6th 05 12:37 PM
External web query - insert rows Victoria Johnson via OfficeKB.com New Users to Excel 0 April 5th 05 10:15 PM


All times are GMT +1. The time now is 03:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"