I read this article about importing batch Excel Data Into Oracle data. I cannot help but share a test example I wrote last year. This example is used in the background of a Web project I created last year. In fact, it is very simple to upload the Execl file and then read the data and write it into the database. At that time, I also searched for some information on the Internet, but there was a lot of ready-made code, but the problem occurred when I copied it and used it, the Excel file uploaded in the background can only read the content of the first worksheet, but cannot be read after the second worksheet, that is, the database cannot be imported after the second worksheet, when it was very depressing, I finally saw a solution from a netizen in a Foreign Forum. In fact, the code is very simple. I also simply encapsulated it. I don't need to talk about it anymore. paste the Code directly and I am done ..
Code /*************************************** *****************************
Filename: UpLoadExcelToSql. cs
Created: 2009/04/16
Author: liaoyun
Purpose: import data to the database based on the uploaded Excel File
**************************************** *****************************/
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Collections. Generic;
Using System. Data. OleDb;
Using System. Text;
Using System. Data. SqlClient;
/// <Summary>
/// Summary of UpLoadExcelToSql
/// </Summary>
Public class UpLoadExcelToSql
{
Private string conStringExcel; // excel connection string
Private string excelFilePath; // Excel file path
// The connection string should be obtained from the configuration file
Private string connectionString = "Data Source = a3421387dce54fa \ SQL2005; Initial Catalog = Northwind; Integrated Security = True ";
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "excelFileName"> Excel file name </param>
Public UpLoadExcelToSql (string excelFilePath)
{
This. excelFilePath = excelFilePath;
This. conStringExcel = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" +
ExcelFilePath +"