C # read Excel data to DataSet
*/
///<summary>
///read data source
/// </summary>
///<param name= "Filenameurl" ></PARAM>
// /<param name= "table" ></param>
///<returns></returns>
public DataSet Execleds (string Filenameurl, String table)
{
& nbsp; DataSet ds = new DataSet ();
Try
{
String strconn = "Provider=Microsoft.Jet.OLEDB.4.0 +" + "data source=" + Filenameurl + "; extended properties= ' Excel 8.0; Hdr=yes; Imex=1 ' ";
OleDbConnection conn = new OleDbConnection (strconn);
Conn.Open ();
Microsoft.office.interop.excel.application objexcelfile = new Microsoft.office.interop.excel.application ();
Microsoft.office.interop.excel._workbook Objworkbook;
Microsoft.office.interop.excel._worksheet Objimportsheet;
Objexcelfile.displayalerts = false;
Objworkbook = Objexcelfile.workbooks.open (filenameurl, 0, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
Objimportsheet = (microsoft.office.interop.excel._worksheet) objworkbook.sheets[1];
String tablename = Objimportsheet.name.tostring ();
OleDbDataAdapter Odda = new OleDbDataAdapter ( "SELECT * FROM [" + tablename + "$]", conn);
Odda.fill (ds, table);
conn.close ();
Objworkbook.close (false, Type.Missing, Type.Missing);
objexcelfile.quit ();
objworkbook = null;
objimportsheet = null;
objexcelfile.workbooks.close ();
killprocess ("Excel");
Gc.collect ();
}
catch (Exception ex)
{
Response.Write (Ex.tostring ());
}
return DS;
}