我正在从事电子商务网站项目,但有一些我无法解决的问题。这是我的数据访问层代码部分。
try
{
using (SqlConnection con = new SqlConnection(Security.ConnString))
{
using (SqlCommand cmd = new SqlCommand("Login", con))
{
cmd.CommandTimeout = (60 * 60);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@xx", xx);
cmd.Parameters.AddWithValue("@xx", xx);
cmd.Parameters.AddWithValue("@Ip", Ip);
cmd.Parameters.AddWithValue("@SessionId", SessionId);
if (con.State != ConnectionState.Open)
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
if (dr["Result"].ToString() == "1")
{
x = LoadDataRecordMusteri(dr);
x.Result = new ResultModel();
x.Result.Code = 56;
x.Result.Description = "kk";
}
else
{
x.Result = new ResultModel();
x.Result.Code = 86;
x.Result.Description = dr["Result"].ToString();
}
if (x.Durum == false)
{
x.Result = new ResultModel();
x.Result.Code = 24;
x.Result.Description = "xx";
}
}
else
{
x.Result = new ResultModel();
x.Result.Code = 23;
x.Result.Description = "aa";
}
}
}
}
}
catch (Exception ex)
{
x.Result = new ResultModel();
x.Result.Code = 57;
x.Result.Description = ex.Message;
}
return x;
}
在dr.Read()
之前,一切都很美好。在sql中,当我执行它时,它的工作原理;但只要我调试我的代码,它就会抛出我:
else
{
x.Result = new ResultModel();
x.Result.Code = 23;
x.Result.Description = "aa";
}
我尝试了很多东西,但我做不到。感谢帮助。