定义的字段太多 [英] Too many fields defined

查看:53
本文介绍了定义的字段太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网络应用中读取包含40列的Excel文件,但在运行之后,我收到了此错误。

  许多 字段 定义

描述: 未处理 例外 发生 < span class =code-leadattribute>
执行 当前 web 请求 review stack trace for 更多 信息 关于 错误 其中 it originated 代码

异常 详情: 系统数据 OleDb OleDbException: 许多 字段 已定义





我的代码是:



 OleDbConnection oleconn = new OleDbConnection(Provider = Microsoft.Jet.OLEDB.4.0;+ 
Data Source =+ strFilePath +; Jet OLEDB:引擎类型= 5;+
扩展属性=''Excel 8.0; IMEX = 1; HDR = NO'');
DataTable tbl = new DataTable();


OleDbCommand cmdSelect = new OleDbCommand(@SELECT * FROM [+ SheetName +$],oleconn);
OleDbDataAdapter ole_adapter = new OleDbDataAdapter();
ole_adapter.SelectCommand = cmdSelect;
oleconn.Open();
ole_adapter.Fill(tbl);
oleconn.Close();
ole_adapter = null;
return tbl;

解决方案

,oleconn);
OleDbDataAdapter ole_adapter = new OleDbDataAdapter();
ole_adapter.SelectCommand = cmdSelect;
oleconn.Open();
ole_adapter.Fill(tbl);
oleconn.Close();
ole_adapter = null;
return tbl;


不要使用*来检索列,而是使用方括号[]的列名,如下所示。 />
尝试使用一些列,然后全部使用。

 OleDbCommand cmdSelect =  new  OleDbCommand( @  SELECT [Column1],[Column2] FROM [ + SheetName +   


,oleconn);


Hi, I''m trying to read Excel File with 40 columns in my web apps ,but after running it ,I got this error.

Too many fields defined.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Too many fields defined.



My Code is this :

OleDbConnection oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
         "Data Source=" + strFilePath + ";Jet OLEDB:Engine Type=5;" +
         "Extended Properties=''Excel 8.0;IMEX=1;HDR=NO''");
        DataTable tbl = new DataTable();


        OleDbCommand cmdSelect = new OleDbCommand(@"SELECT * FROM [" + SheetName + "$]", oleconn);
        OleDbDataAdapter ole_adapter = new OleDbDataAdapter();
        ole_adapter.SelectCommand = cmdSelect;
        oleconn.Open();
        ole_adapter.Fill(tbl);
        oleconn.Close();
        ole_adapter = null;
        return tbl;

解决方案

", oleconn); OleDbDataAdapter ole_adapter = new OleDbDataAdapter(); ole_adapter.SelectCommand = cmdSelect; oleconn.Open(); ole_adapter.Fill(tbl); oleconn.Close(); ole_adapter = null; return tbl;


Don''t use * for retrieving the columns, rather use the column names with square brackets "[]" like below.
Try with some columns, then go for all.

OleDbCommand cmdSelect = new OleDbCommand(@"SELECT [Column1], [Column2] FROM [" + SheetName + "


", oleconn);


这篇关于定义的字段太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆