关于excel宏向数据库插入数据报错
  cConnect = "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=root;SERVER=testdb;PWD=root"

    For i = 1 To iEndrow
        Lotid = Sheets("lotlist").Range(Cells(iEndrow, "A"), Cells(iEndrow, "A")).Value
        sqlstr = "insert into mfg_tb_autopri_wait_terList values('" + Lotid + "','" + iuser + "','" + itime + "')"

         With ActiveSheet.QueryTables.Add(Connection:=cConnect, Destination:=Range("A1"))

            .CommandText = sqlstr
            .Name = "查询来自 FP8DB"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False  
        End With

    Next

这段报错,原本这段是查询用的。查询用以下这段是没问题的
With ActiveSheet.QueryTables.Add(Connection:=cConnect, Destination:=Range("A1"))

        .CommandText = sqlstr
        .Name = "查询来自 FP8DB"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = True
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .Refresh BackgroundQuery:=False  
    End With
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐