現時点では、私は特定のサイト(asp.net)をphpでビルドするために十分な長さのライブを維持しようとしています。しかし、私は.netやasp.netについてよく分かりません。指定されたキャストは有効ではありません
私たちは、このエラーを取得しています
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
データベースか何かからの結果をキャストする問題があるように見えます。使用されるコード:
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;
}
}
}
これはどこが間違っているのですか?
コードの記述方法は、SQL文「SELECT ID from ledenlijst」の結果として、有効なIDが常に必要であるように見えます。 InvalidCastExceptionの原因となるレコードが返されない場合別の原因は、IDがint以外のフィールドである可能性があります。このコードは時々動作し、失敗することがありますか? – rsbarro