我使用的是mysql数据库,如果我执行这个解决方案,我会得到catch块中的异常,下面是我的代码
MySqlManager dac = new MySqlManager();
long value = 0;
DbCommand dbCommand = dac.GetStoredProcCommand("Spforgotpassword");
dac.AddOutParameter(dbCommand, "p_op_EmailId", DbType.Int32, -1);
dac.AddInParameter(dbCommand, "p_p_EmailId", DbType.String, data.Email_Id);
dac.AddInParameter(dbCommand, "p_p_Password", DbType.String, Generatehash256(data.Password));
dac.AddInParameter(dbCommand, "p_P_EncryptedPassword", DbType.String, Encryption.Encrypt(data.Password));
dac.AddInParameter(dbCommand, "p_P_Mode", DbType.String, 102);
dac.AddInParameter(dbCommand, "p_IPAddress", DbType.String, data.IPAddress);
IDataReader reader = dac.ExecuteReader(dbCommand);
if (reader.Read())
{
value = reader["result"] == DBNull.Value ? default(long) : Convert.ToInt32(reader["result"]);
}
dac.CloseConnection(dbCommand, reader);
if (Convert.ToBoolean(ConfigurationSettings.AppSettings["EnableEmail"]))
{
if (Convert.ToInt32(dac.GetParameterValue(dbCommand, "p_op_EmailId")) != -1)
{
Mail.WebMail oWebmail = new Mail.WebMail(dac.GetParameterValue(dbCommand, "p_op_EmailId").ToString());
}
}
return value;
一旦我执行了这一行,我就会得到一个异常---object不能从dbnull转换到其他类型
dac.GetParameterValue(dbCommand, "p_op_EmailId")
p\u op\u emailid是输出参数。
1条答案
按热度按时间omvjsjqw1#
看起来存储过程设置了
p_op_EmailId
至null
. 所以你不能把它转换成Int32
直接。相反,您可以将其强制转换为可为null的int,并将其合并为
-1
比较前: