我无法从oledb C#更新excel文件中的数据

时间:2017-02-27 06:45:26

标签: c# excel oledb

我有一个很大的Excel文档,所以我决定使用OleDbconneciton来打开和编辑它。打开它时没问题。我只是像SQL一样使用Select命令,但当我尝试从某些列更改数据时,我收到错误 - >条件表达式中的数据类型不匹配。 这是更新字符串生成器的示例:

<body onload="getIBDQData();">
    <div class="wrapper bgImg">

        <div class="searchCnt formCnt height801 clearfix">
            <div class="container containerIbdq">



                        <label id='l_startDate' style="margin-left: 30px;">Start Date:</label> 
                        <input type="text" id="startDate" style="margin-bottom: 15px;" >

                        <label id='l_endDate' style="margin-bottom: 15px;" >End Date:</label>
                        <input type="text" id="endDate" style="margin-bottom: 15px;">

                        <input type="button" value="Go" name="go" style="margin-bottom: 20px;" onclick="getIBDQData();"/>

                        <label class="radio-inline" style="margin-left :30px; margin-bottom: 10px;" >Aggregate</label>
                        <input type="radio" id="aggregateList" name="optradio" value="A" style="margin-bottom: 5px;" checked="checked" />

                        <label class="radio-inline"  style="margin-bottom: 10px;">Breakout</label>
                        <input type="radio" id="breakoutList" name="optradio" value="B" style="margin-bottom: 5px;" />




                </div>
            </div>
        </div>

        <div class=" clearfix insidepage">
            <div class="gridCnt">

<table id="aggregateTable" border="0" cellspacing="0" cellpadding="0"
                    class="grid" width="100%" style="margin-top:-20px;">
                    <thead>
                        <tr style="background-color: silver;">
                            <th style="width:214.5px;">----------------</th>
                            <c:if test="${not empty dataList}">

                                <c:forEach items="${dataList}" var="listValue">
                                    <c:if test="${listValue.key =='aggregateList' }">

                                        <c:forEach items="${listValue.value}" var="listItem">
                                            <th style="width:218px;" ><a href="javascript:void(0)"  data-toggle="modal" data-target="#myModal" class="show" id="${listItem.fiscalMonth}">${listItem.fiscalMonth}</a></th>
                                        </c:forEach>

                                    </c:if>
                                </c:forEach>
                            </c:if>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td style="text-align:left;">Total IB Count</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='aggregateList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.totalIBCount}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">Total Hardware Count (Active IB)</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='aggregateList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.totalHWCount}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">IB DQ % (All Attribute)</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='aggregateList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.dqPercent}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">IB DQ % (Top 10 Attribute)</td>

                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='aggregateList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.tomTenAttributeDQPercent}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <c:if test="${empty  dataList}">
                            <tr align="center">
                                <font color="red">No Data Found !!!</font></
                            <tr>
                        </c:if>
                    </tbody>
                </table>
                <table id="breakoutTable" border="0" cellspacing="0" cellpadding="0"
                    class="grid" width="100%" style="margin-top:-20px;">
                    <thead>
                        <tr style="background-color: silver;">
                            <th style="width:214.5px;">----------------</th>
                            <c:if test="${not empty dataList}">
                                <c:forEach items="${dataList}" var="listValue">
                                    <c:if test="${listValue.key =='breakoutList' }">
                                        <c:forEach items="${listValue.value}" var="listItem">
                                            <th style="width:218px;" ><a href="#" data-toggle="modal" data-target="#myModal" class="show" id="${listItem.fiscalMonth}">${listItem.fiscalMonth}</a></th>
                                        </c:forEach>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td style="text-align:left;">Total IB Count</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='breakoutList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.totalIBCount}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">Total Hardware Count (Active IB)</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='breakoutList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.totalHWCount}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">IB DQ % (All Attribute)</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='breakoutList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.dqPercent}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <tr>
                            <td style="text-align:left;">IB DQ % (Top 10 Attribute)</td>
                            <c:forEach items="${dataList}" var="listValue">
                                <c:if test="${listValue.key =='breakoutList' }">
                                    <c:forEach items="${listValue.value}" var="listItem">
                                        <td style="text-align:right;" >${listItem.tomTenAttributeDQPercent}</td>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </tr>
                        <c:if test="${empty  dataList}">
                            <tr align="center">
                                <font color="red">No Data Found !!!</font>
                            <tr>
                        </c:if>

                    </tbody>
                </table>

<table id="aggreDQtable" border="0" cellspacing="0" cellpadding="0"
                    class="grid" width="100%" >
                        <thead>
                        <tr style="background-color: silver;">
                                <th style="width: 200px;text-align:left;" onclick="sortTable(0)">Attribute</th> 
                                <th onclick="sortTable(1)" style="width: 102.5px;">DQ</th>   
                                <th onclick="sortTable(2)" style="width: 102.5px;">QTY</th>  
                                <th onclick="sortTable(3)" style="width: 102.5px;"> DQ</th>  
                                <th onclick="sortTable(4)" style="width: 102.5px;">QTY </th>    
                                <th onclick="sortTable(5)" style="width: 102.5px;">DQ</th>  
                                 <th onclick="sortTable(6)" style="width: 102.5px;">QTY</th>
                                 <th onclick="sortTable(7)" style="width: 102.5px;">DQ</th>
                                 <th onclick="sortTable(8)" style="width: 102.5px;">QTY</th>
                                 <th onclick="sortTable(9)" style="width: 102.5px;">DQ</th>
                                 <th onclick="sortTable(10)" style="width: 102.5px;">QTY</th>    
                                 <th onclick="sortTable(11)" style="width: 102.5px;">DQ</th>    
                                 <th onclick="sortTable(12)" style="width: 102.5px;">QTY </th>   
                            </tr>
                        </thead>
                        <tbody>
                            <c:if test="${not empty dataList}">
                                <c:forEach items="${dataList}" var="listValue">
                                    <c:if test="${listValue.key =='dqAggrList' }">
                                        <c:forEach items="${listValue.value}" var="listItem">
                                    <tr id="${listItem.attribute}">
                                        <td style="text-align:left;">${listItem.attribute}</td>
                                        <td style="text-align:right;">${listItem.dQ1}</td>
                                        <td style="text-align:right;">${listItem.qty1}</td>
                                        <td style="text-align:right;">${listItem.dQ2}</td>
                                        <td style="text-align:right;">${listItem.qty2}</td>
                                        <td style="text-align:right;">${listItem.dQ3}</td>
                                        <td style="text-align:right;">${listItem.qty3}</td>
                                        <td style="text-align:right;">${listItem.dQ4}</td>
                                        <td style="text-align:right;">${listItem.qty4}</td>
                                        <td style="text-align:right;">${listItem.dQ5}</td>
                                        <td style="text-align:right;">${listItem.qty5}</td>
                                        <td style="text-align:right;">${listItem.dQ6}</td>
                                        <td style="text-align:right;">${listItem.qty6}</td>
                                    </tr>
                                        </c:forEach>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty  dataList}">
                            <tr align="center">
                                <font color="red">No Data Found !!!</font>
                            <tr>
                        </c:if>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        </tfoot>

                        </table>

<table id="breakDQtable" border="0" cellspacing="0" cellpadding="0"
                    class="grid" width="100%" >
                        <thead>
                            <tr style="background-color: silver;"  >
                                <th style="width: 200px;text-align:left;"   onclick="sortBreakTable(0)">Attribute</th>  
                                <th  onclick="sortBreakTable(1)" style="width: 102.5px;">DQ</th>     
                                <th  onclick="sortBreakTable(2)" style="width: 102.5px;">QTY</th>    
                                <th  onclick="sortBreakTable(3)" style="width: 102.5px;"> DQ</th>    
                                <th  onclick="sortBreakTable(4)" style="width: 102.5px;">QTY </th>  
                                <th  onclick="sortBreakTable(5)" style="width: 102.5px;">DQ</th>    
                                 <th  onclick="sortBreakTable(6)" style="width: 102.5px;">QTY</th>
                                 <th onclick="sortBreakTable(7)" style="width: 102.5px;">DQ</th>
                                 <th  onclick="sortBreakTable(8)" style="width: 102.5px;">QTY</th>
                                 <th onclick="sortBreakTable(9)" style="width: 102.5px;">DQ</th>
                                 <th onclick="sortBreakTable(10)" style="width: 102.5px;">QTY</th>   
                                 <th  onclick="sortBreakTable(11)" style="width: 102.5px;">DQ</th>  
                                 <th  onclick="sortBreakTable(12)" style="width: 102.5px;">QTY </th>     
                            </tr>
                        </thead>
                        <tbody>
                            <c:if test="${not empty dataList}">
                                <c:forEach items="${dataList}" var="listValue">
                                    <c:if test="${listValue.key =='dqBreakList' }">
                                        <c:forEach items="${listValue.value}" var="listItem">
                                    <tr  id="${listItem.attribute}">
                                        <td style="text-align:left;">${listItem.attribute}</td>
                                        <td style="text-align:right;">${listItem.dQ1}</td>
                                        <td style="text-align:right;">${listItem.qty1}</td>
                                        <td style="text-align:right;">${listItem.dQ2}</td>
                                        <td style="text-align:right;">${listItem.qty2}</td>
                                        <td style="text-align:right;">${listItem.dQ3}</td>
                                        <td style="text-align:right;">${listItem.qty3}</td>
                                        <td style="text-align:right;">${listItem.dQ4}</td>
                                        <td style="text-align:right;">${listItem.qty4}</td>
                                        <td style="text-align:right;">${listItem.dQ5}</td>
                                        <td style="text-align:right;">${listItem.qty5}</td>
                                        <td style="text-align:right;">${listItem.dQ6}</td>
                                        <td style="text-align:right;">${listItem.qty6}</td>
                                    </tr>
                                        </c:forEach>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty  dataList}">
                            <tr align="center">
                                <font color="red">No Data Found !!!</font>
                            <tr>
                        </c:if>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        </tfoot>
                        </table>

在出口时,它得到:

 this._updateCommand = string.Format("UPDATE [{0}${1}{2}:{1}{2}] SET F{3} = ?", workSheet, ((DATA_COL)this._cellIndex).ToString(), this._rowIndex, "1");

NEXTSTEP:

"UDPATE [worksheet$B1:B1] SET F1 = ?"

那么,我做错了什么?

1 个答案:

答案 0 :(得分:0)

您应该尝试将IMEX更改为2或0.到目前为止,我没有在文档中看到IMEX=3提及。这是新事物还是你有错字?以下是MS doc关于IMEX值的说法:

  

0是导出模式 - 用于写入/插入Excel文件
  1是导入模式 - 用于从Excel文件读取
  2是链接模式(完全更新功能)

有关写入Excel的IMEX设置的更多详细信息,请参阅此答案:https://stackoverflow.com/a/42413128/5857386

HTH