title: Specified cast is not valid
body: <p>At the moment I'm trying to keep a certain site  (asp.net) alive long enough for its replacement to be build in php. However I don't know much about .net or asp.net.</p>
  
  <p>We are getting this error:</p>
  
  <pre><code>Specified cast is not valid.
  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.InvalidCastException: Specified cast is not valid.
  
  Source Error:
  
  Line 21:                     string conn = ConfigurationSettings.AppSettings["DSN"];
  Line 22:                     string email = (Membership.GetUser(HttpContext.Current.User.Identity.Name)).Email;
  Line 23:                     iD = (int)SqlHelper.ExecuteScalar(
  Line 24:                         conn,
  Line 25:                         CommandType.Text,
  
  
  Source File: e:\PKwebSX\app_code\PKMembershipProvider.cs    Line: 23
  
  Stack Trace:
  
  [InvalidCastException: Specified cast is not valid.]
     PKMembershipProvider.get_ID() in e:\PKwebSX\app_code\PKMembershipProvider.cs:23
     ASP.mijnpk_ascx.Page_Load(Object sender, EventArgs e) in e:\PKwebSX\mijnpk.ascx:20
     System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +36
     System.Web.UI.Control.OnLoad(EventArgs e) +102
     System.Web.UI.Control.LoadRecursive() +47
     System.Web.UI.Control.LoadRecursive() +131
     System.Web.UI.Control.LoadRecursive() +131
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1064
  
  
  Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET Version:2.0.50215.44
  </code></pre>
  
  <p>It looks like there's a problem casting a result from the database or something. The code used:</p>
  
  <pre><code>public sealed class PKMembershipProvider : SqlMembershipProvider
  {
      public int ID
      {
          get
          {
              int iD = 0;
              if (HttpContext.Current.User.Identity.IsAuthenticated)
              {
                  string conn = ConfigurationSettings.AppSettings["DSN"];
                  string email = (Membership.GetUser(HttpContext.Current.User.Identity.Name)).Email;
                  iD = (int)SqlHelper.ExecuteScalar(
                      conn,
                      CommandType.Text,
                      "SELECT ID From ledenlijst WHERE email = '" + email + "'");
              }
              return iD;
          }
      }
  }
  </code></pre>
  
  <p>Can anybody tell me where this is going wrong?</p>