You will need to define data types for columns in your DataTable. I create a small sample to help you out
SQL
CREATE TABLE [dbo].[tblPersons](
[PersonId] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NOT NULL,
[Salary] [numeric](10, 3) NOT NULL
) ON [PRIMARY]
GO
Namespaces
using System.Configuration;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
string excelPath = Server.MapPath("~/Files/Persons.xls");
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelPath + ";Extended Properties=;Excel 8.0;HDR=YES;IMEX=1";
using (OleDbConnection excel_con = new OleDbConnection(connString))
{
excel_con.Open();
string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
DataTable dtExcelData = new DataTable();
dtExcelData.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Salary",typeof(decimal)) });
using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
{
oda.Fill(dtExcelData);
}
excel_con.Close();
string consString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(consString))
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
{
bulkCopy.DestinationTableName = "dbo.tblPersons"; // Table Name
bulkCopy.ColumnMappings.Add("ID", "PersonId");
bulkCopy.ColumnMappings.Add("Name", "Name");
bulkCopy.ColumnMappings.Add("Salary", "Salary");
con.Open();
bulkCopy.WriteToServer(dtExcelData);
con.Close();
}
}
}
}
Screenshots

