Public datatable getdatatablefromexcel (string URL ){
// Create connection string variable. Modify the "Data Source"
// Parameter as appropriate for your environment.
String sconnectionstring = "provider = Microsoft. Jet. oledb.4.0;" +
"Data Source =" + URL + ";" + "extended properties = Excel 8.0 ;";
// Create connection object by using the preceding connection string.
Oledbconnection objconn = new oledbconnection (sconnectionstring );
// Open connection with the database.
Objconn. open ();
// The code to follow uses a SQL SELECT command to display the data from the worksheet.
// Create new oledbcommand to return data from worksheet.
Oledbcommand objcmdselect = new oledbcommand ("select * from [sheet1 $]", objconn );
// Create new oledbdataadapter that is used to build a dataset
// Based on the preceding SQL SELECT statement.
Oledbdataadapter objadapter1 = new oledbdataadapter ();
// Pass the SELECT command to the adapter.
Objadapter1.selectcommand = objcmdselect;
// Create new dataset to hold information from the worksheet.
Dataset objdataset1 = new dataset ();
// Fill the dataset with the information from the worksheet.
Objadapter1.fill (objdataset1, "xldata ");
Datatable dt = objdataset1.tables ["xldata"];
// Clean up objects.
Objconn. Close ();
Return DT;
}