我有一个问题。有没有办法更改下面的代码,以便将Excel电子表格数据上传到DB2数据库?以下代码将数据从DB2下载到excel电子表格。
我想将数据下载到excel,在excel中操作它,最后上传到数据库
Sub CreateQueryTableWithParameters()
Dim qryTable As QueryTable
Dim rngDestination As Range
Dim strConnection As String
Dim strSQL As String
With Sheets("Sheet1")
.Activate
.Range("A:XFD").Clear
End With
' Define the connection string and destination range.
strConnection = "ODBC;DSN=RDBWC;UID=;PWD=;DBALIAS=RDBWC;"
Set rngDestination = Sheet1.Range("A1")
' Create a parameter query.
strSQL = "SELECT *"
strSQL = strSQL & " FROM PDB2I.DI_NOS_OST_MVT_01 "
' Create the QueryTable.
Set qryTable = Sheet1.QueryTables.Add(strConnection, rngDestination)
' Populate the QueryTable.
qryTable.CommandText = strSQL
qryTable.CommandType = xlCmdSql
qryTable.Refresh False
End Sub
答案 0 :(得分:0)
见Import Excel spreadsheet columns into SQL Server database。第五个答案显示了如何执行INSERT语句。请注意,您必须为要上载(或更新)的Excel工作表中的每一行执行INSERT语句。