Click here to Skip to main content
15,891,909 members
Articles / Programming Languages / C#

SQL Query Results as Excel Spreadsheet Mailer Web Service

Rate me:
Please Sign up or sign in to vote.
4.67/5 (17 votes)
4 Oct 2003CPOL4 min read 175.4K   591   60  
Web Service that e-mails results of a SQL Query as Excel Spreadsheet attachments
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Threading;

namespace Hosca.SQLExcelMail
{
	/// <summary>
	/// Summary description for Service1.
	/// </summary>
	[WebService(Namespace="http://www.hosca.com/webservices/SQLExcelMail")]
	public class SQLExcelMail : System.Web.Services.WebService
	{
		public SQLExcelMail()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion

[WebMethod]
public void SendQueryResultsAsSpreadSheet(string ConnectString, string SQLQuery, string EmailAddress)
{
	// create our worker class
	ExcelQueryProcessor eqp = new ExcelQueryProcessor(ConnectString,SQLQuery,EmailAddress);
	// queue it 
	ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessRequest),eqp);
}

private void ProcessRequest(Object stateInfo) {
	// cast stateInfo back to an ExcelQueryProcessor 
	ExcelQueryProcessor eqp  = (ExcelQueryProcessor)stateInfo;
	// off we go ...
	eqp.GenerateExcelSheet(); 
}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer JPMorgan Chase & Co.
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions