我有以下函数需要在另一个函数中调用。我不知道该怎么做?
private int IsValidUser()
{
int result = 0;
string strQuery = "Select Email From AUser Where Email = @Email And Password = @Password ";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand Cmd = new SqlCommand(strQuery, con);
//Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
Cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
con.Open();
result = (int)Cmd.ExecuteScalar();
if (result > 0)
{
//Session["SessionEmail"] = txtEmail.Text;
Session[General.S_USEREMAIL] = txtEmail.Text;
Response.Redirect("~/frmMyAccountMyProfile.aspx");
}
else
{
Literal1.Text = "Invalid Email/Password!";
}
}
我试图在按钮单击事件中将其称为如下。
protected void btnSignIn_Click(object sender, EventArgs e)
{
// Authenticate User
bool blnValidUser = false;
IsValidUser();
blnValidUser = Convert.ToBoolean(IsValidUser().result.Value);
if (blnValidUser)
{
// on Success - If remember me > Save to cookies
//SaveUserDetailsToCookie();
}
else
{
// on Failure - Show error msg
}
}