Hi mzmishra]Hi
private void Button1_Click(object sender, System.EventArgs e)
{
//this function will open an existing excel file and put the info into the dataset.
//from dataset you can now easily create a connection and another function that will append these records
//into your database...
//drag and drop the following object contron in your webform:
//1. Datagrid
//2. HTML File Field object control
//first specify the path and filename of your excel
string PathFilename = this.File1.PostedFile.FileName.ToString() ;
//second is specify the sheet name you want to read
string strSheetName = "Sheet1";
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DS;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0;data source='" + PathFilename + "'; Extended Properties=Excel 8.0;");
//Select the data from Sheet1 of the workbook.
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [" + strSheetName + "$]", MyConnection);
DS = new System.Data.DataSet();
MyCommand.Fill(DS);
MyConnection.Close();
MyConnection.Dispose();
this.DataGrid1.DataSource=DS;
this.DataGrid1.DataBind();
}
Best Regards,
Ruel
Hi,
Can anybody send me the code sample to read one excel file and write the content of the excel file to database.It is very urgent .
Please help me on the same.