W
Wing Chan
Hi,
I am trying to upload data from excel to sql with the following piece of
code. However, I keep getting the syntax error on my update statement. Can
anyone give me some insights?
Thanks a million
Dim sheetname as string
Dim sqltable1 as string
sheetname = "[Upload$]"
sqltable1 = "['MSDASQL', 'DRIVER={SQL
Server};SERVER=testserver;Trusted_Connection=yes', " & db &
"..GLBUDFIL_SQL_TESTWC] as A"
sqltable = "A"
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Trim(txtFilePath.Text) & ";" & _
"Extended Properties=Excel 8.0"
cn.BeginTrans
'update first
strSQL = "UPDATE " & sqltable1 & _
" JOIN " & sheetname & _
" ON " & sqltable & ".MN_NO= " & sheetname & ".MN_NO " & _
" SET " & sqltable & ".[acct_budget_1] = " & sheetname &
".[acct_budget_1] "
cn.Execute strSQL, lngRecsUdt, adExecuteNoRecords
I am trying to upload data from excel to sql with the following piece of
code. However, I keep getting the syntax error on my update statement. Can
anyone give me some insights?
Thanks a million
Dim sheetname as string
Dim sqltable1 as string
sheetname = "[Upload$]"
sqltable1 = "['MSDASQL', 'DRIVER={SQL
Server};SERVER=testserver;Trusted_Connection=yes', " & db &
"..GLBUDFIL_SQL_TESTWC] as A"
sqltable = "A"
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Trim(txtFilePath.Text) & ";" & _
"Extended Properties=Excel 8.0"
cn.BeginTrans
'update first
strSQL = "UPDATE " & sqltable1 & _
" JOIN " & sheetname & _
" ON " & sqltable & ".MN_NO= " & sheetname & ".MN_NO " & _
" SET " & sqltable & ".[acct_budget_1] = " & sheetname &
".[acct_budget_1] "
cn.Execute strSQL, lngRecsUdt, adExecuteNoRecords