使用c#读取Excel时列名不匹配 [英] Column name mismatch in Excel while reading it using c#

查看:55
本文介绍了使用c#读取Excel时列名不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#代码读取一个excel,并将其保存到datatable

但是数据表中的列标题与excel不同。

excel中的列名好像很受欢迎。为什么?



可能是什么原因?



注意:我在excel中的列名是lenghty。 ('sdsd'组织名称,如果它与dwiccc组织不同这是excel专栏,但它的到来就像



sdsd'组织名称,如果它不同于dwiccc Org在我的数据表中



下面是使用的连接字符串

OleDbConnection connection = new OleDbConnection(Provider = Microsoft。 ACE.OLEDB.12.0;数据源=+路径+;扩展属性= Excel 8.0);



请帮我解决这个问题。



任何解决方案?

Am reading one excel using c# code, and am saving it in to datatable
but the column heading in datatable is differnt from the excel.
Column name in excel seems to be trimed. why?

What could be the reason?

Note:My column name in excel is lenghty. ( " 'sdsd' Organisation Name if it is different from the dwiccc Organisation " this is excel column but its coming like

" sdsd' Organisation Name if it is different from the dwiccc Org" in my datatable)

below is the connction string am using
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0");

Please help me to solve this.

Any solution?

推荐答案

您的列名对于您尝试存储的数据库来说太长了。



坚持64个字符或更少。



实际上要少得多,这个列太过笨拙了名称,你应该避免空格和特殊字符





一个例子(好) SQL服务器命名标准 [ ^ ]
Your column name is too long for the database you are trying to store it on.

Stick to 64 characters or less.

Actually MUCH less, this is far too unwieldy as a column name and you should avoid spaces and special characters as well


An example of (good) SQL server naming standards[^]


解决方案1非常好......



我建议你使用别名;)



请阅读:使用ODBC在Excel和SQL Server之间获取数据 [ ^ ]。在那里你会找到许多有用的信息。
Solution 1 is very, good...

I would recommend you to use aliases ;)

Please, read it: Getting Data between Excel and SQL Server using ODBC [^]. There you'll find many useful information.


这篇关于使用c#读取Excel时列名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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