1
我嘗試創建登錄方法,並在此登錄方法我嘗試調用這樣登錄通過實體框架
更新的代碼
存儲過程當我嘗試這一點,並在按鈕點擊這個節目像在 '/' 應用這個..
服務器錯誤。類型 'System.Exception的' 的
引發異常。
按鈕代碼:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
loginmethod(txt_us.Text, txt_pwd.Text);
}
catch(Exception)
{
throw new Exception();
}
}
public bool loginmethod(string UserName,string Password)
{
TrackDataEntities1 td = new TrackDataEntities1();
// splogin_Result sp=td.splogin(UserName,Password);
splogin1_Result sp = td.splogin1(UserName, Password).FirstOrDefault();
if(sp.Password == txt_pwd.Text)
{
return true;
}
else
{
return false;
}
}
當我在模型中添加存儲過程我設置返回類型複雜類型splogin和複雜的名字是splogin1_Result和功能導入的名字是splogin1
現在splogin1_Result
public partial class splogin1_Result : ComplexObject
{
#region Factory Method
/// <summary>
/// Create a new splogin1_Result object.
/// </summary>
/// <param name="userName">Initial value of the UserName property.</param>
/// <param name="password">Initial value of the Password property.</param>
public static splogin1_Result Createsplogin1_Result(global::System.String userName, global::System.String password)
{
splogin1_Result splogin1_Result = new splogin1_Result();
splogin1_Result.UserName = userName;
splogin1_Result.Password = password;
return splogin1_Result;
}
#endregion
#region Simple Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String UserName
{
get
{
return _UserName;
}
set
{
OnUserNameChanging(value);
ReportPropertyChanging("UserName");
_UserName = StructuralObject.SetValidValue(value, false, "UserName");
ReportPropertyChanged("UserName");
OnUserNameChanged();
}
}
private global::System.String _UserName;
partial void OnUserNameChanging(global::System.String value);
partial void OnUserNameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Password
{
get
{
return _Password;
}
set
{
OnPasswordChanging(value);
ReportPropertyChanging("Password");
_Password = StructuralObject.SetValidValue(value, false, "Password");
ReportPropertyChanged("Password");
OnPasswordChanged();
}
}
private global::System.String _Password;
partial void OnPasswordChanging(global::System.String value);
partial void OnPasswordChanged();
#endregion
}
'splogin()'方法返回一個'ObjectResult'(* many * of'splogin_Result'),而調用該方法的代碼需要一個'splogin_Result'作爲回報。也許你需要'td.splogin(UserName,Password).SingleOrDefault()'或者改變你的方法來返回一個'splogin_Result'而不是'ObjectResult ' –
haim770
請檢查更新 – user6628729
現在你的'loginmethod()'正在返回錯誤的類型。你將它定義爲返回'bool'而你居然'返回sp'。也許'返回sp!= null'是你需要的嗎? – haim770