To upload your Excel data into Sql server database using Windows application

I want to share code to Upload Excel data into Sql database.

For this design a form like below Image

 
Upload.JPG
 
On the click of Upload button
 
private void btnUpload_Click(object sender, EventArgs e)
{
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data
Source=" + txtFilePath.text.trim() + ";Extended Properties=Excel 8.0");
connection.Open();
OleDbDataAdapter adap = new OleDbDataAdapter("select * From [Sheet1$]", connection);
dt = new DataTable();
adap.Fill(dt);

 if(dt.Rows.count>0)
 {
 for(int i=0; i<dt.Rows.count; i++)
 {
 // Here declare Sqlcommand and Find data from dt.
 }
 }
 }

If you getting any exception or msg like "
Microsoft.ACE.OLEDB.12.0 provider is not registered"
 
Then click here to download "Microsoft Access Database Engine" .After downloading install this setup to avoid above exception.