本文介绍了将OleDBDataAdapter与Excel 2003一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个Excel 2003文件,在电子表格上有一个表 我可以使用dataadapter成功填充数据表和datagridview 当我来使用更新命令但是我总是得到并发错误,我不相信它是并发错误,但这似乎是零记录的默认错误消息更新 连接字符串是 Provider = Microsoft.ACE.OLEDB.12.0;数据源= F: \ My Folder \ Myy Sheet.xls; < br /> 扩展属性=Excel 8.0; HDR = YES; 测试的更新声明是 更新[My_Sheet $]设置[部件代码] =''__ foo''其中([部件代码]如''* OQ2 *'') 更新代码为 公共 Sub 更新( ByVal 值 As PartsList.PartsListDataTableDataTable) 尝试 我 .m_oDataAdapter.UpdateCommand.Connection.Open() 我 .m_oDataAdapter.Update(value) Catch ex As DBConcurrencyException 停止 最后 如果 我 .m_oDataAdapter.UpdateCommand.Connection.State = ConnectionState.Open 然后 我 .m_oDataAdapter.UpdateCommand.Connection.Close() 结束 尝试 结束 Sub 错误的详细信息是: System.Data.DBConcurrencyException被捕获 消息:并发冲突:UpdateCommand影响了预期的1条记录中的0条。 堆栈跟踪是: 在System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent,BatchCommandInfo [] batchCommands,Int32 commandCount) 在System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent,BatchCommandInfo [] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.Update(DataRow [] dataRows,DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable,DataTableMapping tableMapping) 在System.Data.Common.DbDataAdapter.Update(DataTable dataTable) at DO_Tools.PartsListDataAdapter.Update(PartsListDataTableDataTable value)in C:\ Users \ Me\documents\visual studio 2010 \Projects\DO_Tools \DO_Tools \_DataAdapters \PartsListDataAdapter.vb:第168行 我已更改语法但错误仍然存在 任何人都可以提出一个建议,说明为什么这不起作用?解决方案 我找到了解决方案 我已经为更新命令添加了所有列的参数但是我在测试期间没有使用所有这些参数,只有规范和部件代码,甚至这些在测试期间都没有在更新命令中使用。 通过更改update命令,只添加在参考中引用的参数更新命令,然后更新操作正常。 修订更新命令: 更新[My_Sheet I have an Excel 2003 file that has a table on a spreadsheetI can successfully fill a datatable and a datagridview using a dataadapterWhen I come to use the update command however I always get a concurrency error, I don''t believe it''s a concurrency error but that seems to be the default error messages for zero records updatedThe connection string is Provider=Microsoft.ACE.OLEDB.12.0;Data Source= F:\My Folder\My Sheet.xls; <br />Extended Properties="Excel 8.0;HDR=YES";The update statement for testing is Update [My_Sheet$] Set [Part Code]=''__foo'' where ([Part Code] like ''*OQ2*'')The update code isPublic Sub Update(ByVal value As PartsList.PartsListDataTableDataTable) Try Me.m_oDataAdapter.UpdateCommand.Connection.Open() Me.m_oDataAdapter.Update(value) Catch ex As DBConcurrencyException Stop Finally If Me.m_oDataAdapter.UpdateCommand.Connection.State = ConnectionState.Open Then Me.m_oDataAdapter.UpdateCommand.Connection.Close() End TryEnd SubError detail is: System.Data.DBConcurrencyException was caughtMessage: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. The stack trace is: at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)at DO_Tools.PartsListDataAdapter.Update(PartsListDataTableDataTable value) in C:\Users\Me\documents\visual studio 2010\Projects\DO_Tools\DO_Tools\_DataAdapters\PartsListDataAdapter.vb:line 168 I''ve changed the syntax but the error persistedCan anyone offer a suggestion why this is not working? 解决方案 这篇关于将OleDBDataAdapter与Excel 2003一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 14:53