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 ();
// The code to follow uss 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" ", Objconn;
// create new oledbdataadapter That is used to build a dataset // based on the preceding sql select statement. OLEDBDATADAPTER OBJADAPTER1 = New OLEDBDATADAPTER ();
// 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;
}