使用文件路径导入excel到db [英] import excel to db with file path

查看:101
本文介绍了使用文件路径导入excel到db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Excel工作表导入sql server表。我已经编写了数据访问层。



但是我无法使用Microsoft.Jet.OLEDB.4.0并且我想使用Microsoft.office.interop.excel。



这可以作为参考添加并导入到bin。



如何获取确切的文件路径通过命令行获取excel。



任何建议或代码片段请求?

。谢谢。

解决方案



如果您只需要将数据导入到数据库,那么您可以使用SQL Server的Excel导入实用程序执行相同的

而无需代码。

如果您有特定目的或任何数据操作,请告诉我。


两种方式:

解决方案1 ​​ - 以编程方式:

1)通过 ADO.NET(ACE.OLEDB) [ ^ ]使用此连接字符串 [ ^ ]

2)将数据提取到数据表对象中

3)通过SqlBulkCopy [ ^ ](首先需要连接到MS SQL服务器)。



解决方案2 - 手动:

http://sqlwithmanoj.com/tag/microsoft-ace-oledb-12-0/ [ ^ ]


excel imp ort实用程序对我来说没有用。我之前尝试过。

由于目前遗留的转换,我在sql中将日期作为字符串。

日期搜索不使用sql导入工作。这是设计现在。由于某种原因,这是不能改变的。



有人可以指出我在c#中的提示。请。

I am trying to import an excel sheet into sql server table. I have written the data access layer.

However I am unable to use Microsoft.Jet.OLEDB.4.0 and I want to use Microsoft.office.interop.excel.

This can be added as reference and imported to bin.

How to get the exact file path for the excel via command line.

any suggestion or code snippet pleasE?
.Thanks.

解决方案

Hi,
If you have to simply excel import to database then you can do the same
with Excel import utility of SQL Server without code.
Let me know if you have some specific purpose or any data manupulation or not.


Two ways:
Solution 1 - programmatically:
1) to connect to the MS Excel workbook via ADO.NET (ACE.OLEDB)[^] using this connection string[^]
2) fetch data into datatable object
3) populate data into MS SQL server via SqlBulkCopy[^] (first you need to be connected to MS SQL server).

Solution 2 - manually:
http://sqlwithmanoj.com/tag/microsoft-ace-oledb-12-0/[^]


The excel import utility is not useful for me here..I tried it before.
Im having date as a string in sql due to legacy transformation at the moment.
the date search dont work using sql import. This is by design for now.This cant be changed for a reason.

can someone point me hints in c# . please.


这篇关于使用文件路径导入excel到db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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