I have to create a web app. that prints out the statistics for student applicants in a .txt file. The data in form of Tables resides in a SQL server. Now, the user provides a date range(for eg. from 12/1/2006 to 1/1/2007) and the outputted text file will have the following:
- The Number of applications received
- The number of applications approved
- Number of students with a criminal background and the type of background
- Number of applicants who applied last year.
I was wondering that from a design standpoint, what would be an elegant and effecient way to extract the data from the server, store it in some kind of data structure and output the contents in a text file. I was looking at Enterprise library and interfaces but wasn't sure if that's a good way to work on a project like this one. Any advise will be appreciated.
Thanks

ReportGeneration Application
osamaT
Vaassu
PeteDev1
This is not an area where I have much experience, but I think the problem has to do with the fact that you are in a web app, and hence in a sandbox of sorts. Try running the same code from a Win Forms or Console Application, and if it works, then you know the problem has to do with security and web apps. You might to sign your web app before you can use it to access system resources.
- Charlie
Syed Mazhar Hasan
In most cases, you should not need an intermediate data structure for a problem of this kind. You should be able to compose a single SQL statement that will return your data in sequential rows that you can access easily with basic classes like SqlDataReader and SqlCommand. It is just a question of finding the right SQL statement, then use cookie cutter code to iterate over the data.
Here is sample code from the Visual Studio help file:
private static void ReadOrderData(string connectionString) { string queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Call Read before accessing data. while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1])); } // Call Close when done reading. reader.Close(); } }- Charlie
Jonas.S
Thanks a lot..but here's the thing, when I declare something like this:
Excel.Application oXL = new Excel.Application();
I get an exception as follows:
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access is
denied.
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5
or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account, and
check the boxes for the desired access.
Source Error:
Line 155: //Open the HTML file in Excel.
Line 156:
Line 157: Excel.Application oExcel = new Excel.Application();
Line 158: oExcel.Visible=true;
Line 159: oExcel.UserControl=true;
Line 157 is where it is getting stuck. Can somebody point out what the problem might be
Ori&#39;
JAXN
Thanks for the response. Are you talking about datagrid data here What I am trying to do here is export data(data extracted from the sql server) in a format specified by an excel template. I am not sure whether I should use datagrids here..I am using datasets and datatables and then using the data in the datatable to populate the spreadsheet cell by cell. This is all being done in a separate class which deals exclusively with populating the spreadsheet.
I am just trying to figure out why should the application throw an exception when I do something as follows:
Excel.Application xcl =
new Excel.Application();Thanks
fjcardoso
Take a look at this link. See if it helps
http://www.c-sharpcorner.com/Code/2004/March/ExcelReportsInNet.asp
Matthijs Koopman