Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to type 'System.IConvertible'. 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: Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to type 'System.IConvertible'. Source Error: Line 76: cmd.Parameters.Add(parameter); Line 77: } Line 78: return Convert.ToBoolean(cmd.ExecuteReader()); Line 79: } Line 80: }
<pre>using Authentication_Model.DAL; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; namespace Authentication_Model.Accounts { public partial class ResetPassword : System.Web.UI.Page { SqlCommand cmd; protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { if(!IsPasswordResetLinkValid()) { Response.Write("<script>alert('Password reset link has expired or is invalid')</script>"); } } } protected void btnResetChange_Click(object sender, EventArgs e) { if(ChangeUserPassword()) { Response.Write("<script>alert('Password changed successfully')</script>"); } else { Response.Write("<script>alert('Password reset link has expired or is invalid')</script>"); } } public bool ChangeUserPassword() { List<SqlParameter> paramList = new List<SqlParameter>() { new SqlParameter() { ParameterName = "@GUID", Value = Request.QueryString["uid"] }, new SqlParameter() { ParameterName = "@Password", Value = FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPassword.Text, "SHA1") } }; return ExecuteSP("sp_ChangePassword", paramList); } public bool IsPasswordResetLinkValid() { List<SqlParameter> paramList = new List<SqlParameter>() { new SqlParameter() { ParameterName = "@GUID", Value = Request.QueryString["uid"] } }; return ExecuteSP("sp_IsPasswordResetLinkValid", paramList); } public bool ExecuteSP(string SP_Name, List<SqlParameter> SP_Parameters) { using (cmd = new SqlCommand()) { cmd.Connection = Connection.GetConnection(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "sp_IsPasswordResetLinkValid"; foreach (SqlParameter parameter in SP_Parameters) { cmd.Parameters.Add(parameter); } return Convert.ToBoolean(cmd.ExecuteReader()); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)