I want to share code to Upload Excel data into
Sql database.
For this design a form like below Image
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.
}
}
}
|
Then click
here to download "Microsoft Access Database Engine" .After downloading
install this setup to avoid above exception.