To upload your excel data in .net windows forms, design a form like below.
{
// Here declare Sqlcommand and Find data from dt.
}
On the brows button write the code to select the file from your hard drive
private void btnUpload_Click(object sender, EventArgs e)
{
OpenFileDialog ofd=new OpenFileDialog();
if(ofd.ShowDialog()==DialogResult.OK)
{
txtFilePath.Text=ofd.FileName;
}
}
private void btnUpload_Click(object sender, EventArgs e)
{
OleDbConnection objCon= 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
}
}
No comments:
Post a Comment