using System.Data.OleDb;
using System.Data.SqlClient;
public partial class newtask : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
string strConnection = "Data Source=172.18.25.55;Initial Catalog=master;Integrated Security=True";
string path = FileUploadExcel.PostedFile.FileName;
string excelConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;Data Source=C:\\trail.xls; Extended Properties=Excel 8.0;Persist Security Info=False";
OleDbConnection excelconnection=new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[Designation] from [Sheet1$]", excelconnection);
excelconnection.Open();
OleDbDataReader dReader;
dReader=cmd.ExecuteReader();
SqlBulkCopy sqlBulk=new SqlBulkCopy (strConnection);
sqlBulk.DestinationTableName="Excel";
sqlBulk.WriteToServer(dReader);
excelconnection.Close();
////string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
}
}
Nishadullas, if this helps please login to Mark As Answer. | Alert Moderator