Excel 2010 to Sql Server 2008 Insert Statment -


i going excel sql. have connection established. can create simple select statment , obtain values table in sql excel. now, want go other way. trying insert value excel sql. keep getting "operation not allowed when object closed" error # 3704. below code.

option explicit private conn adodb.connection  private sub commandbutton1_click()     dim conn adodb.connection dim rs adodb.recordset dim sconnstring string  'this create string connect.  sconnstring = "driver={sql server};data source=**;initial catalog = **;trusted_connection =yes;"    'create connection , recordset objects.  set conn = new adodb.connection set rs = new adodb.recordset    'open connection in order execute.  conn.open sconnstring set rs = conn.execute("insert testtable(testcolumn) values('50');")        'check data.  if not rs.eof      sheets(1).range("a1").copyfromrecordset rs    'close connection  rs.close  else     msgbox "error: no records returned.", vbcritical end if        'clean     if cbool(conn.state , adstateopen) conn.close     set conn = nothing     set rs = nothing   end sub 

how execute statement? said earlier select statment worked fine. did

("select * kpisetupoee;") 

any thoughts? thank time

an insert statement doesn't return records, why trying assign results recordset? change line:

set rs = conn.execute("insert testtable(testcolumn) values('50');") 

to execute:

conn.execute("insert testtable(testcolumn) values('50');") 

then clean code rid of unneeded recordset references.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -