简体   繁体   中英

VB.net Visual Studio 2003 Reading Data from Excel Table

I am trying to read data from an Excel table into a DataSet however I get an error: "No value given for one or more required parameters." I've done some research and learned that this error usually occurs when a required value is empty ("" in the case of a string) or null. Below is my code.

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()

The error is occuring on cdImport.Fill(dsImport) presumably because there is nothing to fill dsImport with.

After doing some debugging I find that the Server Version field of cnExcel is: error: an excpetion of type: {System.InvalidOperationException} occured

What am I doing wrong?

Just in case anyone was wondering about how this got resolved: I wound up just sending the excel file as a csv to my server. The server then runs a stored procedure on the file which returns a table to my application. A dataset is then filled from this table.

You may need to put additional quotes around the Extended Properties=Excel 5.0; part of your connection string (see connectionstrings.com for more information)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM