Click here to Skip to main content
15,883,983 members
Articles / Web Development / ASP.NET

A reporting service using SOAP calls passing XML to a Data Extension

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
19 Oct 2005CPOL8 min read 85.4K   406   26  
Demostrates how to render a report by passing XML to a data extension via SOAP calls.
// File: DataSetDataReader.cs

using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Xml;

using Microsoft.ReportingServices.DataProcessing;

namespace CustomDataExtension
{
	/// <summary>
	/// Description :	A Data Processing Extension IDataReader
	/// </summary>
	public class DataSetDataReader : IDataReader 
	{
		private System.Data.DataSet	_dataSet;
		private int	_currentRow;

		public DataSetDataReader(string sXml) 
		{
			try
			{
				BusinessService.BusinessData BusWS = new BusinessService.BusinessData();
				this._dataSet = BusWS.GetReportDataSet(sXml);
				
				//set the current row to one before the first
				_currentRow = -1;
			}
			catch(Exception ex)
			{
				throw new Exception("Error calling web service XML: " + sXml, ex);
			}
		}

		/// <summary>
		/// Moves to the first or next row
		/// </summary>
		/// <returns>True if more data present, false if done</returns>
		public Boolean Read() 
		{
			bool bRet = false;
			int nRowCount = 0;
			try
			{
				Debug.Assert (this._dataSet != null, "Internal Error: this.dataSet should not be null");
				if (this._dataSet != null)
				{
					this._currentRow ++;
					nRowCount = this._dataSet.Tables[0].Rows.Count;
					if (this._currentRow >= nRowCount) 
					{
						//Debug.WriteLine("DataReader: Done with all rows");
						bRet = false;
					} 
					else 
					{
						//Debug.WriteLine("DataReader: Moved to row " + this._currentRow);
						bRet = true;
					}
				}
			}
			catch (Exception ex)
			{
				Debug.WriteLine("DataReader failed. " + ex.Message);
			}
			return bRet;
		}

		/// <summary>
		/// Retrieves the number of fields per row
		/// </summary>
		public int FieldCount 
		{
			get 
			{
				return(this._dataSet.Tables[0].Columns.Count);
			}
		}

		/// <summary>
		/// Retrieves the name of a field
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The name of the specified field</returns>
		public String GetName(int Index) 
		{
			return(this._dataSet.Tables[0].Columns[Index].ColumnName);
		}

		/// <summary>
		/// Retrieves the data type of a field
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The data type of the specified field</returns>
		public Type GetFieldType(int Index) 
		{
			return(this._dataSet.Tables[0].Columns[Index].DataType);
		}

		/// <summary>
		/// Gets the value of a field on the current row
		/// </summary>
		/// <param name="Index">The index of the field</param>
		/// <returns>The value of the column</returns>
		public Object GetValue(int Index) 
		{
			return(this._dataSet.Tables[0].Rows[this._currentRow][Index]);
		}

		/// <summary>
		/// Retrieves the ordinal of a field based on the field name
		/// </summary>
		/// <param name="Name">The name of the field</param>
		/// <returns>The ordinal of the specified field</returns>
		public int GetOrdinal(string Name) 
		{
			//Debug.WriteLine("DataReader.GetOrdinal(" + Name + ")");
			int nRet = 0;
			try 
			{
				nRet = (this._dataSet.Tables[0].Columns[Name].Ordinal);
			} 
			catch // (Exception ex) 
			{
				// throw new Exception("Ordinal [" + Name + "] not found.", ex);
			}

			return nRet;
		}

		/// <summary>
		/// Dispose of any held resources
		/// </summary>
		public void Dispose() {}
	}
}

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
Software Developer (Senior) LEN Associates Inc.
United States United States
Years of software consulting and software development using Microsoft development products such as Microsoft Content Management System, SQL Server Reporting Service, ASP.Net C# VB.Net, HTML and javascript web development, Visual Studio add-on development, C++ MFC/ATL and COM+ development, and ActiveX components.

Comments and Discussions