title: Getting a Cast Exception
body: <p>I am using Linq 2 SQL and I am getting this error message when firing the button click event "Specified cast not valid", the stack trace is below. I am new to using linq to sql and trying to get away from ADO.NET, which it is working, by the way, using ADO.NET, calling a stored procedure.</p>
  
  <blockquote>
    <p>[InvalidCastException: Specified cast is not valid.]
       System.Data.SqlClient.SqlBuffer.get_Decimal() +5299638
       System.Data.SqlClient.SqlDataReader.GetDecimal(Int32 i) +68
       Read_GetBreakDownsResult(ObjectMaterializer<code>1 ) +3730
       System.Data.Linq.SqlClient.ObjectReader</code>2.MoveNext() +32
       System.Collections.Generic.List<code>1..ctor(IEnumerable</code>1 collection) +381
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
       GuhringWebsite2.ReportingPortal.Default.LoadBreakDowns(Object sender, EventArgs e) in c:\WillieDevonSmith\GuhringWebsite2\Reporting\Reports\Default.aspx.cs:51
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724</p>
  </blockquote>
  
  <p>Here is the code which calls the stored procedure using linq 2 sql, which I am passing in a static value for testing.</p>
  
  <pre><code>    ReportsDataContext reportsdbContext = new ReportsDataContext();
  
      var query = reportsdbContext.GetBreakDowns("0070917819");
      GridView1.DataSource = query;
      GridView1.DataBind();
  </code></pre>
  
  <p>In the designer.cs class it gets excuted here</p>
  
  <pre><code>    [global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetBreakDowns")]
      public ISingleResult&lt;GetBreakDownsResult&gt; GetBreakDowns([global::System.Data.Linq.Mapping.ParameterAttribute(Name="BillToCustomerNo", DbType="NVarChar(20)")] string billToCustomerNo)
      {
          IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), billToCustomerNo);
          return ((ISingleResult&lt;GetBreakDownsResult&gt;)(result.ReturnValue));
      }
  </code></pre>
  
  <p>My Stored Procedure looks like this</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[GetBreakDowns] 
  -- Add the parameters for the stored procedure here
  @BillToCustomerNo nvarchar(20)
  AS
  BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  SET NOCOUNT ON;
  
  -- Insert statements for procedure here
  SELECT DivName,SUM(CASE WHEN BillingDateYY = '2010' THEN totalvalue ELSE 0 END) 
  AS '2010',SUM(CASE WHEN BillingDateYY = '2011' THEN totalvalue ELSE 0 END) 
      AS '2011',SUM(CASE WHEN BillingDateYY = '2012' THEN totalvalue ELSE 0 END)
          AS '2012',SUM(CASE WHEN BillingDateYY = '2013' THEN totalvalue ELSE 0 END)
              AS '2013',SUM(CASE WHEN BillingDateYY = '2014' THEN totalvalue ELSE 0 END)   
                  AS '2014', sum(totalvalue) FROM  [ReportData].[dbo].[Sales] WHERE BillToCustomerNo in (@BillToCustomerNo) 
                      GROUP BY DivName
  UNION 
  SELECT 'Total'As 'DivName',SUM(CASE WHEN BillingDateYY = '2010' THEN totalvalue ELSE 0 END) 
      AS '2010',SUM(CASE WHEN BillingDateYY = '2011' THEN totalvalue ELSE 0 END) 
          AS '2011',SUM(CASE WHEN BillingDateYY = '2012' THEN totalvalue ELSE 0 END) 
              AS '2012',SUM(CASE WHEN BillingDateYY = '2013' THEN totalvalue ELSE 0 END)
                  AS '2013',SUM(CASE WHEN BillingDateYY = '2014' THEN totalvalue ELSE 0 END)
                      AS '2014',sum(totalvalue) FROM  [ReportData].[dbo].[Sales] WHERE BillToCustomerNo in (@BillToCustomerNo)
  END
  </code></pre>