且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有oledb连接的情况下将数据从Excel导入到asp.net c#中的sql数据库

更新时间:2023-10-18 08:53:58

您需要知道要插入的位置记录.为此,您需要具有连接字符串(基本上是db信息).如果您不想在web.config中拥有它,则可以在.cs文件本身中拥有它.
也许此链接会为您提供帮助.
从Excel导入SQL数据 [
You need to know where you are inserting records. For that you need to have the connection string (basically db information). If you don''t want to have it in web.config, then you have it in the .cs file itself.
Perhaps this link would help you.
SQL Import Data from Excel[^]


使用openrowset选项:

Using openrowset option :

select * into #temp_table
    from openrowset
    (
        'Microsoft.Jet.OLEDB.4.0',
        'Excel 8.0;Database=C:\Useless\Temp\sample.xls',
        [Customer_Account_Details


);




运行查询时,请确保您的Excel文件实际上已关闭,否则将收到提供程序错误,并且该文件的路径是相对于服务器的.




Please make sure that your Excel file is actually closed when you run the query or otherwise you will receive provider error, and the path to the file is relative to the server.