I'm getting the following error while trying to redirect to another aspx page.

Here is the sequence of events. From the default.aspx page, I click on the
IO (MenuControl) button and get redirected to
Io.aspx. The Io.aspx page displays fine, but when I try to redirect somewhere
else, either via a MenuControl button or a
linkbutton on the Io.aspx page, I get the error. A redirect to from default.aspx
to any other page works just fine.

I've been trying to resolve this for four days now! Please help.

The aspx page and code-behind are included as additional threads.

************************************************************************************


Server Error in '/SiteWizard' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
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.FormatException: Input string was not in a correct
format.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.

Stack Trace:


[FormatException: Input string was not in a correct format.]
System.Number.ParseDecimal(String s, NumberStyles style, NumberFormatInfo
info) +0
System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider)
+30
System.Xml.XmlConvert.ToDecimal(String s)
System.Data.Common.DecimalStorage.ConvertXmlToObject(String s)
System.Data.DataColumn.ConvertXmlToObject(String s)
System.Data.XmlDataLoader.LoadData(DataRow& row, DataTable parentTable,
Boolean[] foundColumns)
System.Data.XmlDataLoader.LoadData(DataTable parentTable)
System.Data.XmlDataLoader.LoadData(XmlReader reader)
System.Data.DataSet.ReadXmlDiffgram(XmlReader reader)
System.Data.DataSet.ReadXml(XmlReader reader, XmlReadMode mode)
System.Data.DataSet..ctor(SerializationInfo info, StreamingContext context)

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target,
SerializationInfo info, StreamingContext context) +0
System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object
obj, SerializationInfo info, StreamingContext context) +149
System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder
holder) +95
System.Runtime.Serialization.ObjectManager.DoFixups() +170
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage methodCallMessage)
+248
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage
methodCallMessage) +190
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream) +11
System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader)
System.Web.SessionState.SessionDictionary.Deserialize(BinaryReader reader)
System.Web.SessionState.StateClientManager.Deserialize(Stream stream,
DateTime lockDate, Int32 lockCookie)
System.Web.SessionState.OutOfProcStateClientManager.DoGet(String id, StateProtocolExclusive
exclusiveAccess)
System.Web.SessionState.OutOfProcStateClientManager.GetExclusive(String
id)
System.Web.SessionState.StateClientManager.BeginGetExclusiveSync(String
id, AsyncCallback cb, Object state)
System.Web.SessionState.OutOfProcStateClientManager.BeginGetExclusive(String
id, AsyncCallback cb, Object state)
System.Web.SessionState.SessionStateModule.GetSessionStateItem()
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source,
EventArgs e, AsyncCallback cb, Object extraData)
System.Web.AsyncEventExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET
Version:1.0.3705.288


***********************************************************************************

Io.aspx page

<%@ Register TagPrefix="ft" TagName="FooterUserControl" Src="Footer.ascx"
%>
<%@ Register TagPrefix="hd" TagName="HeaderUserControl" Src="Header.ascx"
%>
<%@ Page language="c#" Codebehind="Io.aspx.cs" AutoEventWireup="false" Inherits="SiteWizard.FrmIo"
%>
<%@ Register TagPrefix="menu" TagName="MenuControl" Src="MenuControl.ascx"
%>
<%@ Register TagPrefix="srch" TagName="SearchControl" Src="SearchControl.ascx"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Io View</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="/Includes/StyleGray.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="FrmIo" method="post" runat="server">
<input type=hidden id=HdnReportDate name=HdnReportDate value="<%= Property.ReportDate
%>">
<input type=hidden id=HdnSiteRepresentationId name=HdnSiteRepresentationId
value="<%= Property.SiteRepresentationId %>">
<input type=hidden id=HdnArmId name=HdnArmId value="<%= Property.ArmId
%>"> <input type=hidden id=HdnCategoryId name=HdnCategoryId value="<%= Property.CategoryId
%>">
<input type=hidden id=HdnParentSiteId name=HdnParentSiteId value="<%=
Property.ParentSiteId %>">
<table height="100%" width="100%">
<% if ((bool)Session["IsExcel"] == false) { %>
<tr>
<td height="1" colspan="2"><hd:headerusercontrol id="HeaderUserControl"
runat="server"></hd:headerusercontrol></td>
</tr>
<tr>
<td colspan="2" height="1">
<table height="1" cellSpacing="0" width="100%">
<tr>
<td><menu:MenuControl id="MenuControl" runat="server"></menu:MenuControl></td>
</tr>
<tr>
<td><srch:SearchControl id="SearchControl" runat="server"></srch:SearchControl></td>
</tr>
</table>
</td>
</tr>
<tr>
<td noWrap width="1%" height="1"><asp:dropdownlist id="DrpDateSelect"
runat="server" AutoPostBack="True"></asp:dropdownlist></td>
<td align="middle" width="99%" height="1"><font size="+1"><b>IO View</b></font></td>
</tr>
<tr>
<td height="1" colSpan="2"><asp:label id="LblPageDescription" runat="server"
EnableViewState="true"></asp:label></td>
</tr>
<% } %>
<tr>
<td height="1" colspan="2">datagrid goes here</td>
</tr>
<% if ((bool)Session["IsExcel"] == false) { %>
<tr>
<td height="100%" colspan="2" valign="bottom"><ft:footerusercontrol
id="FooterUserControl" runat="server"></ft:footerusercontrol></td>
</tr>
<% } %>
</table>
</form>
<% Session["IsExcel"] = false; %>
</body>
</HTML>

*****************************************************************************************

Io.aspx.cs code-behind

public class FrmIo : System.Web.UI.Page
{
public Properties Property = new Properties(); // Maxw.ClassLib
public Names Name = new Names(); // Maxw.ClassLib
public DatesTimes DateTime = new DatesTimes(); // Maxw.ClassLib
protected System.Web.UI.WebControls.DropDownList DrpDateSelect;
protected System.Web.UI.HtmlControls.HtmlInputHidden HdnReportDate;
protected System.Web.UI.HtmlControls.HtmlInputHidden HdnSiteRepresentationId;
protected System.Web.UI.HtmlControls.HtmlInputHidden HdnArmId;
protected System.Web.UI.HtmlControls.HtmlInputHidden HdnCategoryId;
protected System.Web.UI.HtmlControls.HtmlInputHidden HdnParentSiteId;

protected MenuControl MenuControl;
protected SearchControl SearchControl;

private void Page_Load(object sender, System.EventArgs e)
{
if ( !Page.IsPostBack )
{
try
{
Property.ReportDate = Server.UrlDecode(Request.QueryString["ReportDate"].ToString());
}
catch
{
Property.ReportDate = "mtd"+DateTime.GetCurrentDate().ToString();
}
try
{
Property.SiteRepresentationId = Convert.ToInt32(Request.QueryString["SiteRepresentationId"].ToString());
}
catch
{
Property.SiteRepresentationId = -1;
}
try
{
Property.ArmId = Convert.ToInt32(Request.QueryString["ArmId"].ToString());
}
catch
{
Property.ArmId = -1;
}
try
{
Property.CategoryId = Convert.ToInt32(Request.QueryString["CategoryId"].ToString());
}
catch
{
Property.CategoryId = -1;
}
try
{
Property.ParentSiteId = Convert.ToInt32(Request.QueryString["ParentSiteId"].ToString());
}
catch
{
Property.ParentSiteId = -1;
}
ViewState["SortAscending"] = "yes";
Property.Frequency = DateTime.GetFrequency(Property.ReportDate).ToString();
Property.ReportDateWoPrefix = DateTime.RemoveFrequencyPrefix(Property.ReportDate).ToString();
BindData();
DrpDateSelect.Items.FindByValue(Property.ReportDate).Selected = true;
}

if ( Page.IsPostBack )
{
Property.ReportDate = DrpDateSelect.SelectedItem.Value.ToString();
Property.SiteRepresentationId = Convert.ToInt32(Request.Form["HdnSiteRepresentationId"].ToString());
Property.ArmId = Convert.ToInt32(Request.Form["HdnArmId"].ToString());
Property.CategoryId = Convert.ToInt32(Request.Form["HdnCategoryId"].ToString());
Property.ParentSiteId = Convert.ToInt32(Request.Form["HdnParentSiteId"].ToString());
Property.Frequency = DateTime.GetFrequency(Property.ReportDate).ToString();
Property.ReportDateWoPrefix = DateTime.RemoveFrequencyPrefix(Property.ReportDate).ToString();
}

SearchControl.ReportDate = Property.ReportDate;
MenuControl.BtnIo.Visible = false;
MenuControl.QueryString = "ReportDate="+Server.UrlEncode(Property.ReportDate)+"&SiteRepresentationId="+Property.Site RepresentationId+"&ArmId="+Property.ArmId+"&CategoryId="+Property.CategoryId+"&ParentSiteI d="+Property.ParentSiteId+"&Field01=IoName";
}


***********************************************************************

MenuControl user control

<%@ Register TagPrefix="srch" TagName="SearchControl" Src="SearchControl.ascx"
%>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="MenuControl.ascx.cs"
Inherits="SiteWizard.MenuControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table width="100%">
<tr>
<td class="DarkColor" align="left" valign="top" width="100%" height="1">
<asp:Button id="BtnSiteRepresentation" runat="server" Text="Site Representation"
CssClass="Button" CausesValidation="False"></asp:Button>
<asp:Button id="BtnArm" runat="server" Text="ARM" CssClass="Button" CausesValidation="False"></asp:Button>
<asp:Button id="BtnCategory" runat="server" Text="Category" CssClass="Button"
CausesValidation="False"></asp:Button>
<asp:Button id="BtnSite" runat="server" Text="Site" CssClass="Button"
CausesValidation="False"></asp:Button>
<asp:button id="BtnIo" runat="server" Text="IO" CssClass="Button" CausesValidation="False"></asp:button>
<asp:button id="BtnIoi" runat="server" Text="IOI" CssClass="Button" CausesValidation="False"></asp:button>
<asp:button id="BtnSalesType" runat="server" Text="SalesType" CssClass="Button"
CausesValidation="False"></asp:button>
<asp:button id="BtnPricingType" runat="server" CausesValidation="False"
CssClass="Button" Text="Pricing Type"></asp:button>
<asp:button id="BtnCostOfRevenue" runat="server" CausesValidation="False"
CssClass="Button" Text="Cost Of Revenue"></asp:button>
<asp:Button id="BtnExcel" Text="Excel" runat="server" CssClass="Button"></asp:Button>
<asp:Button id="BtnArchive" Text="Archive" runat="server" CssClass="Button"></asp:Button>
<asp:Button id="BtnSearch" Text="Site Search" runat="server" CssClass="Button"></asp:Button>
<asp:Button id="BtnReportGenerator" Text="Report Generator" runat="server"
CssClass="Button"></asp:Button>
</td>
</tr>
</table>


MenuControl code-behind.....

public abstract class MenuControl : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.Button BtnArm;
public System.Web.UI.WebControls.Button BtnCategory;
public System.Web.UI.WebControls.Button BtnSite;
public System.Web.UI.WebControls.Button BtnIo;
public SearchControl SearchControl;
public System.Web.UI.WebControls.Button BtnSiteRepresentation;
public string QueryString;

private void Page_Load(object sender, System.EventArgs e)
{
if ( !Page.IsPostBack )
{
Page.FindControl("SearchControl").Visible = false;
}
}

private void BtnSiteRepresentation_Click(object sender, System.EventArgs
e)
{
Session["IsExcel"] = false;
Response.Redirect("Default.aspx?"+QueryString, true);
}

private void BtnArm_Click(object sender, System.EventArgs e)
{
Session["IsExcel"] = false;
Response.Redirect("Arm.aspx?"+QueryString, true);
}

private void BtnCategory_Click(object sender, System.EventArgs e)
{
Session["IsExcel"] = false;
Response.Redirect("Category.aspx?"+QueryString, true);
}

private void BtnSite_Click(object sender, System.EventArgs e)
{
Session["IsExcel"] = false;
Response.Redirect("Site.aspx?"+QueryString, true);
}

private void BtnIo_Click(object sender, System.EventArgs e)
{
Session["IsExcel"] = false;
Response.Redirect("Io.aspx?"+QueryString, true);
}

public string queryString
{
get
{
return QueryString;
}
set
{
QueryString = value;
}
}

*****************************************************************

Properties, Names, and DatesTimes classes

using System;

/// <summary>
/// Maxworldwide Class Library
/// </summary>
namespace Maxw.DataMart.ClassLib
{
/// <summary>
/// Maxworldwide DataMart properties
/// </summary>
public class Properties
{
public int ArmId;
public string ArmName;
public int CategoryId;
public string CategoryName;
public string Frequency;
public int IoId;
public string IoName;
public int IoiId;
public int ParentSiteId;
public string ParentSiteName;
public int PricingTypeId;
public string PricingTypeName;
public string ReportDate;
public string ReportDateWoPrefix;
public int SalesCategoryId;
public string SalesCategoryName;
public int SalesTypeId;
public string SalesTypeName;
public int SiteId;
public string SiteMask;
public string SiteName;
public int SiteRepresentationId;
public string SiteRepresentationName;

public Properties()
{
}

public int armId
{
get
{
return ArmId;
}
set
{
ArmId = value;
}
}

public string armName
{
get
{
return ArmName;
}
set
{
ArmName = value;
}
}

public int categoryId
{
get
{
return CategoryId;
}
set
{
CategoryId = value;
}
}

public string categoryName
{
get
{
return CategoryName;
}
set
{
CategoryName = value;
}
}

public string frequency
{
get
{
return Frequency;
}
set
{
Frequency = value;
}
}

public int ioId
{
get
{
return IoId;
}
set
{
IoId = value;
}
}

public string ioName
{
get
{
return IoName;
}
set
{
IoName = value;
}
}

public int ioiId
{
get
{
return IoiId;
}
set
{
IoiId = value;
}
}

public int parentSiteId
{
get
{
return ParentSiteId;
}
set
{
ParentSiteId = value;
}
}

public string parentSiteName
{
get
{
return ParentSiteName;
}
set
{
ParentSiteName = value;
}
}

public int pricingTypeId
{
get
{
return PricingTypeId;
}
set
{
PricingTypeId = value;
}
}

public string pricingTypeName
{
get
{
return PricingTypeName;
}
set
{
PricingTypeName = value;
}
}

public string reportDate
{
get
{
return ReportDate;
}
set
{
ReportDate = value;
}
}

public string reportDateWoPrefix
{
get
{
return ReportDateWoPrefix;
}
set
{
ReportDateWoPrefix = value;
}
}

public int salesCategoryId
{
get
{
return SalesCategoryId;
}
set
{
SalesCategoryId = value;
}
}

public string salesCategoryName
{
get
{
return SalesCategoryName;
}
set
{
SalesCategoryName = value;
}
}

public int salesTypeId
{
get
{
return SalesTypeId;
}
set
{
SalesTypeId = value;
}
}

public string salesTypeName
{
get
{
return SalesTypeName;
}
set
{
SalesTypeName = value;
}
}

public int siteId
{
get
{
return SiteId;
}
set
{
SiteId = value;
}
}

public string siteMask
{
get
{
return SiteMask;
}
set
{
SiteMask = value;
}
}

public string siteName
{
get
{
return SiteName;
}
set
{
SiteName = value;
}
}

public int siteRepresentationId
{
get
{
return SiteRepresentationId;
}
set
{
SiteRepresentationId = value;
}
}

public string siteRepresentationName
{
get
{
return SiteRepresentationName;
}
set
{
SiteRepresentationName = value;
}
}

}
}

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Maxworldwide Class Library
/// </summary>
namespace Maxw.DataMart.ClassLib
{
/// <summary>
/// Maxworldwide DataMart Get[Name] methods
/// </summary>
public class Names : Properties
{
public Names()
{
}

public string GetArmName(string ReqReportDate, string ReqFrequency, int
ReqArmId)
{
ArmName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetArmName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@ArmId", SqlDbType.Int ) ).Value
= ReqArmId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
ArmName = dr["ArmName"].ToString();
}
catch (InvalidOperationException)
{
ArmName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return ArmName;
}

public string GetCategoryName(string ReqReportDate, string ReqFrequency,
int ReqCategoryId)
{
CategoryName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetCategoryName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@CategoryId", SqlDbType.Int )
).Value = ReqCategoryId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
CategoryName = dr["CategoryName"].ToString();
}
catch (InvalidOperationException)
{
CategoryName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return CategoryName;
}

public string GetIoName(int ReqIoId)
{
IoName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetIoName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@IoId", SqlDbType.Int ) ).Value
= ReqIoId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
IoName = dr["IoName"].ToString();
}
catch (InvalidOperationException)
{
IoName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return IoName;
}

public string GetParentSiteName(string ReqReportDate, string ReqFrequency,
int ReqParentSiteId)
{
ParentSiteName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetSiteName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@SiteId", SqlDbType.Int ) ).Value
= ReqParentSiteId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
ParentSiteName = dr["SiteName"].ToString();
}
catch (InvalidOperationException)
{
ParentSiteName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return ParentSiteName;
}

public string GetPricingTypeName(string ReqReportDate, string ReqFrequency,
int ReqPricingTypeId)
{
PricingTypeName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetPricingTypeName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@PricingTypeId", SqlDbType.Int
) ).Value = ReqPricingTypeId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
PricingTypeName = dr["PricingTypeName"].ToString();
}
catch (InvalidOperationException)
{
PricingTypeName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return PricingTypeName;
}

public string GetSalesCategoryName(string ReqReportDate, string ReqFrequency,
int ReqSalesCategoryId)
{
SalesCategoryName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetSalesCategoryName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@SalesCategoryId", SqlDbType.Int
) ).Value = ReqSalesCategoryId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
SalesCategoryName = dr["SalesCategoryName"].ToString();
}
catch (InvalidOperationException)
{
SiteName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return SalesCategoryName;
}

public string GetSalesTypeName(string ReqReportDate, string ReqFrequency,
int ReqSalesTypeId)
{
SalesTypeName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetSalesTypeName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@SalesTypeId", SqlDbType.Int
) ).Value = ReqSalesTypeId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
SalesTypeName = dr["SalesTypeName"].ToString();
}
catch (InvalidOperationException)
{
SalesTypeName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return SalesTypeName;
}

public string GetSiteName(string ReqReportDate, string ReqFrequency, int
ReqSiteId)
{
SiteName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetSiteName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@SiteId", SqlDbType.Int ) ).Value
= ReqSiteId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
SiteName = dr["SiteName"].ToString();
}
catch (InvalidOperationException)
{
SiteName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return SiteName;
}

public string GetSiteRepresentationName(string ReqReportDate, string ReqFrequency,
int ReqSiteRepresentationId)
{
SiteRepresentationName = "Unknown";
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlCommand cmd = new SqlCommand ( "GetSiteRepresentationName", cn );
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add ( new SqlParameter ( "@ReportDate", SqlDbType.SmallDateTime
) ).Value = ReqReportDate;
cmd.Parameters.Add ( new SqlParameter ( "@Frequency", SqlDbType.VarChar
) ).Value = ReqFrequency;
cmd.Parameters.Add ( new SqlParameter ( "@SiteRepresentationId", SqlDbType.Int
) ).Value = ReqSiteRepresentationId;
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
dr.Read();
try
{
SiteRepresentationName = dr["SiteRepresentationName"].ToString();
}
catch (InvalidOperationException)
{
SiteRepresentationName = "Not Available";
}
}
finally
{
if(cn.State==ConnectionState.Open)
{
cn.Close();
}
}
return SiteRepresentationName;
}

}
}

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Maxworldwide Class Library
/// </summary>
namespace Maxw.DataMart.ClassLib
{
/// <summary>
/// Maxworldwide DataMart Get[Date-Time] methods
/// </summary>
public class DatesTimes : Properties
{
public DatesTimes()
{
}

public string GetCurrentDate()
{
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionStringDataMart"]);
SqlDataReader dr;
SqlCommand cmd = new SqlCommand ( "GetCurrentDate", cn );
cmd.CommandType = CommandType.StoredProcedure;
try
{
cn.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dr.Read();
ReportDate = dr["CurrentDate"].ToString();
dr.Close();
}
finally
{
cn.Close();
}
return ReportDate;
}

public string GetFrequency(string ReqReportDate)
{
if (ReqReportDate.Substring(0,3) == "mtd")
{
Frequency = "Mtd";
}
else
{
Frequency = "Monthly";
}
return Frequency;
}

public string RemoveFrequencyPrefix(string ReqReportDate)
{
if (ReqReportDate.Substring(0,3) == "mtd")
{
ReportDateWoPrefix = ReqReportDate.Substring(3,ReqReportDate.Length-3);
}
else
{
ReportDateWoPrefix = ReqReportDate;
}
return ReportDateWoPrefix;
}

}
}