使用n层更新数据什么都不做

时间:2013-08-04 20:16:21

标签: c# asp.net

我有3层,在业务层执行我的代码我运行代码进行更新

public override bool LoadProperties2List(string TypeOfOperation)
{
  SortedList Sl = new SortedList();

  Sl.Add("@CommandType", TypeOfOperation);
  Sl.Add("@UserName",UserName);
  Sl.Add("@SecondarySchool",SecondarySchool);
  Sl.Add("@University",University);
  Sl.Add("@Qualification",Qualification);
  Sl.Add("@JobTitle",JobTitle);
  Sl.Add("@Company",Company);
  Sl.Add("@PhotoUrl", PhotoUrl);

  ProcedureName = "MangeUserInfo";
  if (db.RunProcedure(ProcedureName, Sl) == 1)
  return true;
  else
  return false;
}

public bool updateUser(string User, string SecondaryS, string Unvi, string Qua, string jobtitle, string company)
{
  this.UserName = User;
  this.SecondarySchool = SecondaryS;
  this.University = Unvi;
  this.Qualification = Qua;
  this.JobTitle = jobtitle;
  this.Company = company;

  if (Update())
  return true;
  else
  return false;
 }

和数据访问层

public void ConnectDB(CommandType CT,string ProNameSQl)
{
  cn = new SqlConnection("Data Source=.;Initial Catalog=Conversation;Integrated Security=True");
  cmd = new SqlCommand();

  cmd.Connection = cn;
  cmd.CommandType = CT;
  cmd.CommandText = ProNameSQl;
  cn.Open();
}

public int RunProcedure(string ProcedureName, SortedList Paraval)
{
  ConnectDB(CommandType.StoredProcedure, ProcedureName);

  for (int x = 0; x < Paraval.Count; x++)
  {
  try
  {

  cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(), Paraval.GetByIndex(x));
  }
  catch
  {
  ;
  }
  }
  return ExceNoneQuery();
}

然后在另一层我使用此方法调用过程进程类并运行

public bool Update()
{
  return LoadProperties2List("u");
  }

在最后一层表示层

我这样做

protected void btnsave_Click(object sender, EventArgs e)
{
  //upadate info
  bool Result = false;
  UsersInfo Upd = new UsersInfo();

  try
  {
  Result = Upd.updateUser(username, TxtSecondarySchool.Text, TxtUniversity.Text, TxtQualification.Text, TxtJobTitle.Text, TxtCompany.Text);
  if (Result==true)

  lblMessage.Text = "Record Updated Successfully.";

  else

  lblMessage.Text = "Record couldn't updated";

  }
  catch (Exception ee)
  {
  lblMessage.Text = ee.Message.ToString();
  }  finally
  {
  Upd = null;
  }
}

当我运行代码时,结果只有

lblMessage.Text = "Record couldn't updated"; 

导致它无法正常工作的错误是什么?

我还发现一些奇怪的事情,即尽管改变原因,文本框不会采用它传递相同值的新值?我需要帮助

1 个答案:

答案 0 :(得分:2)

错误是文本框加载在Page的Startup事件中的例程中,例程放在If IsNotPostback循环之外。因此,默认值只是在每次刷新页面时重新加载,因此看起来是“不可更改的”。