内容简介:http://stackoverflow.com/questions/13352739/error-uploading-excel-file-from-asp-net-application-to-mysql
我正在使用 MySQL 数据库的Web应用程序(ASP.NET).当我尝试通过此应用程序上传Excel文件(.xlsx)时,我没有任何问题.当文件超过24904条记录时,该问题开始.
那时我得到以下错误:
This table contains cells that are outside the range of cells defined in this spreadsheet.
并写入了第24904条记录.
我试图分批加载多个批次,它没有工作.
有什么想法吗?
Dim connExcel As New System.Data.OleDb.OleDbConnection(conStr) Dim cmdExcel As New System.Data.OleDb.OleDbCommand() Dim dt As New DataTable() Dim dataset As New DataSet Dim x As Integer = 2 Dim y As Integer = 20001 Dim range As String = "A" + x.ToString + ":" + "I" + y.ToString cmdExcel.Connection = connExcel If erro = 0 Then Try For i As Integer = 0 To 50 connExcel.Open() dataset.Reset() dataset.Clear() Dim oda As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$" & range.ToString & "]", connExcel) oda.TableMappings.Add("Table", "ExcelTest") oda.Fill(dataset) connExcel.Close() If dataset.Tables(0).Rows.Count > 0 Then SendToDB(dataset) Else i = 50 End If x = x + 20000 y = y + 20000 range = "A" + x.ToString + ":" + "I" + y.ToString Next Label7.Visible = True Label7.Text = "The information has been written successfully from 0 to " + y.ToString Catch ex As Exception Label9.Visible = True Label9.Text = "Database Error 2:" + ex.Message connExcel.Close() End Try End If
我不会使用OLDB或excel,因为它在阅读excel时创建了许多问题
我使用ExcelDataReader https://github.com/ExcelDataReader/ExcelDataReader
尝试这个
Install-Package ExcelDataReader
public static DataSet GetExcelDataSet(string filePath) { FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader; if (Path.GetExtension(filePath) == ".xls") { //Choose one of either 1 or 2 //1. Reading from a binary Excel file ('97-2003 format; *.xls) excelReader = ExcelReaderFactory.CreateBinaryReader(stream); } else { //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); } //Choose one of either 3, 4, or 5 //3. DataSet - The result of each spreadsheet will be created in the result.Tables ////////DataSet result = excelReader.AsDataSet(); //4. DataSet - Create column names from first row excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); //5. Data Reader methods //while (excelReader.Read()) //{ // //excelReader.GetInt32(0); //} //6. Free resources (IExcelDataReader is IDisposable) excelReader.Close(); return result; }
http://stackoverflow.com/questions/13352739/error-uploading-excel-file-from-asp-net-application-to-mysql
以上所述就是小编给大家介绍的《将Excel文件从ASP.NET应用程序上传到MySQL时出错》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- ios – 在TestFlight(iTunes Connect)中为外部测试者提交应用程序时出错
- 如何避免空指针出错?
- 如何避免特效渲染出错?
- OmniROM:“Flex checkpolicy”出错
- Python安装软件包出错
- 让gulp watch出错时不退出
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
PYTHON3:数据分析与机器学习实战
龙马高新教育 / 北京大学出版社 / 2018-9-1 / 69.00
机器学习(Machine Learning, ML)是一门多领域交叉学科,是人工智能的核心,其应用遍及人工智能的各个领域,专门研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能。在机器学习过程中,需要使用大量数据,而数据分析是指用适当的方法对收集的大量数据进行分析,提取有用信息并形成结论,进而对数据加以详细研究和概括总结的过程。本书结合机器学......一起来看看 《PYTHON3:数据分析与机器学习实战》 这本书的介绍吧!