import Data from Excel sheet to SQL Server

Posted by Santosh0683 under ASP.NET category on | Views : 3123
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;

public partial class ExcelToDB : System.Web.UI.Page
string strConnection = ConfigurationManager.ConnectionStrings["StrConnect"].ToString();

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

string MyexcelConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\singh\Desktop\team.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

SqlConnection excelConn = new SqlConnection(MyexcelConnString );

SqlCommand mycmd = new SqlCommand("Select [ID],[Name],[Location] from [Detail$]", excelConn);

SqlDataReader objReader;
objReader = mycmd.ExecuteReader();

SqlBulkCopy objsqlBulk = new SqlBulkCopy(strConnection);
objsqlBulk.DestinationTableName = "Details";



Comments or Responses

Login to post response