【发布时间】:2013-08-15 00:16:01
【问题描述】:
我正在尝试将 Excel 表中的数据读取到数据集中,但是我收到错误消息:“没有为一个或多个必需参数提供值。”我做了一些研究并了解到,当所需的值为空(在字符串的情况下为“”)或 null 时,通常会发生此错误。下面是我的代码。
cnExcel = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & FileName & "; " & _
"Extended Properties=Excel 5.0;")
cdImport = New System.Data.OleDb.OleDbDataAdapter( _
"select * from [" & cSheetName & "$] order by StoreID, ItemID", cnExcel)
dsImport = New System.Data.DataSet
cdImport.Fill(dsImport)
cnExcel.Close()
错误发生在 cdImport.Fill(dsImport) 上大概是因为没有任何东西可以填充 dsImport。
经过调试发现cnExcel的Server Version字段为:error: an excpetion of type: {System.InvalidOperationException}发生
我做错了什么?
【问题讨论】: