Insert Rows From Excel into SQL Server -


i working on insert excel 2010 sql server 2008. have been able insert single cell value sql table excel using push button. trying insert many rows. trying use single loop iterate , insert values. code follows:

option explicit private conn adodb.connection  private sub commandbutton1_click()  dim val1 integer dim integer  dim conn adodb.connection dim sconnstring string  = 1 2  cells(i, 1) = "val1" next  'this create string connect. sconnstring = "driver={sql server};data source=**;initial catalog = **;trusted_connection =yes;"  'create connection , recordset objects. set conn = new adodb.connection  'open connection in order execute. conn.open sconnstring  conn.execute ("insert testtable(testcolumn) values(" & val1 & ")")  'clean if cbool(conn.state , adstateopen) conn.close     set conn = nothing  end sub 

i inserting value table, not values in cells a1:a2. can tell me how loop , insert statement wrong? there better way handle this. know using 2 rows @ moment inserting 1100 rows loop or iterative process needed i'm assuming.

thank time.

you setting val1 incorrectly. change:

cells(i, 1) = "val1" 

to

val1 = cells(i, 1) 

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 -