used a SqlBulkCopy class.
Core Code Analysis
Code I haven't tested yet.
stringExcelconnectionstring =string. Format ("Provider=microsoft.ace.oledb.12.0;data source={0}; Extended Properties=excel 8.0", path); //Create Connection to Excel Workbook using(OleDbConnection connection =NewOleDbConnection (excelconnectionstring)) {OleDbCommand command=NewOleDbCommand ("Select * FROM [sheet1$]", connection); Connection. Open (); //Create DbDataReader to Data Worksheet using(DbDataReader dr =command. ExecuteReader ()) {//SQL Server Connection String stringsqlConnectionString =@"Data source=.\sqlexpress;initial catalog=exceldb;integrated security=true"; //Bulk Copy to SQL Server using(SqlBulkCopy bulkcopy =NewSqlBulkCopy (sqlconnectionstring)) {Bulkcopy.destinationtablename="Employee"; Bulkcopy.writetoserver (DR); Label1.Text="The data has been exported succefuly from Excel to SQL"; } } }
Asp. Net-"Excel"-Bulk load data from Excel into SQL Server database