Sreenath G

Sreenath G

  • NA
  • 233
  • 310.2k

Unable to convert Excel work sheet to Datatable in Windows 2003

Oct 7 2011 4:29 AM
 

Hi,

I am using the following code to convert Excel work sheet to datataable. It is working in my local machine from code. But after deployment in Windows 2003 server this is not reading .XlSX files.  Also, I have Office 2007 and VSTS 2010 in Windows Server. Any ideas on this please.




{





static System.Data.DataTable lFnConvertWorkSheetToDatatblae(string lStrFileName, string aStrWorkSheetName)string lStrConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lStrFileName + ";Extended Properties=Excel 8.0;";OleDbConnection lObjConn = null;OleDbDataAdapter lObjSheetAdapter = null;try

{

System.Data.


{

lObjConn.Open();

lObjSheetAdapter =

lObjSheetAdapter.Fill(lDTSheetData);

}


}


{


}


DataTable lDTSheetData = new System.Data.DataTable();using (lObjConn = new OleDbConnection(lStrConnectionString))new OleDbDataAdapter("select * from [" + aStrWorkSheetName + "$]", lObjConn);return lDTSheetData;catch (Exception)return null;finally

{


{

lObjConn.Close();

lObjSheetAdapter.Dispose();

}


{

lObjConn.Dispose();

}

}

}

if (lObjSheetAdapter != null)if (lObjConn != null)

Answers (9)