To insert data into Excel file from datatable using C# .Net

LAYER: Domain
CLASS: ViewStatisticsManager            
METHOD: WriteToCSV1
MESSAGE: An unknown exception occured in Domain. jp Access is denied.
STACKTRACE:
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(Type objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(Type serverType)

This is the error and it is coming at line which looks like this:
 " objExcel = new Excel.ApplicationClass(); "

I hv MS Excel 11.0 Object Library(MS Office 2003) & OS : MS 2000 Prof.

My task is : To insert data into Excel file from datatable.

This is very urgent need....plzzzzzz reply to this as early as possible
waiting for reply....

Thanking u in anticipation......

ketangholeAsked:
Who is Participating?
 
Thandava VallepalliConnect With a Mentor Commented:
Running office applications from asp.net is not supported by MS, and this KB
article tries to explain why:


http://www.dotnet247.com/247reference/msgs/45/228115.aspx
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757

itsvtk

0
 
Thandava VallepalliCommented:


Alternate is create new excel file using C# code....

send that file path to  below query... the query will insert the data into the excel automatically without creating excel object...

===================================================================
INSERT INTO OPENROWSET ('Microsoft.Jet.OleDB.4.0', 'EXCEL 8.0;Database=f:\Book1.xls', Sheet1$ ) (C1, C2)
SELECT TITLE_ID, TITLE
FROM TITLES
===================================================================

run this query using   command.NonQueryExceute( ) metbod.....

itsvtk
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.