日期:2014-05-17  浏览次数:20445 次

请帮我看看这代码哪有错
弄了两天没弄懂,不知道哪有问题,点击按钮能刷新,但就是没有添加数据到数据库,也没弹出script提示  

UI层
protected void Button2_Click(object sender, EventArgs e)
  {
  string p_adminame = tbusername.Text.Trim();
  string p_adminpwd = tbuserpwd.Text.Trim();  
  bool b = new P_AdminManager().InsertAdmin(p_adminame,p_adminpwd);
  if (b)
  {
  //script:添加成功,此处代码就不写了
  }
  else
  {
  //script:添加失败
  } 
}

BLL层
namespace BLL
{
  public class P_AdminManager
  {
  private P_AdminDAO P_dao = null;
  public P_AdminManager()
  {
  P_dao = new P_AdminDAO();
  }
  public bool InsertAdmin(string p_adminame,string p_adminpwd)
  {
  return P_dao.InsertAdmin(p_adminame,p_adminpwd);
  }
}
}

DAL层
namespace DLL
{
  public class P_AdminDAO
  {
  private SQLHelper sqlhelper;
  public P_AdminDAO()
  {
  sqlhelper = new SQLHelper();
  }
  public bool InsertAdmin(string p_adminame,string p_adminpwd)
  {
  bool flag = false;
  string cmdText = "insert into P_Admin(P_Adminame,P_Adminpwd) values('" + p_adminame + "','" + p_adminpwd + "')";
  SqlParameter[] paras = new SqlParameter[]{
  new SqlParameter("@P_Adminame",p_adminame),
  new SqlParameter("@P_Adminpwd",p_adminpwd)};
  int res = sqlhelper.ExecuteNonQuery(cmdText, paras, CommandType.Text);
  if (res > 0)
  {
  flag = true;
  }
  return flag;
  }
}
}

Model层
namespace Model
{
  public class P_Admin
  {
  private string P_id;
  public string p_id
  {
  get { return P_id; }
  set { P_id = value; }
  }
  private string P_adminame;
  /// 管理员帐户
  public string p_adminame
  {
  get { return P_adminame; }
  set { P_adminame = value; }
  }
  private string P_adminpwd;
  /// 管理员密码
  public string p_adminpwd
  {
  get { return P_adminpwd; }
  set { P_adminpwd = value; }
  }
  private string P_admintype;
  /// 管理员类型
  public string p_admintype
  {
  get { return P_admintype; }
  set { P_admintype = value; }
  }
  public P_Admin()
  { }
  public P_Admin(string P_adminame, string P_adminpwd)
  {  
  this.p_adminame = P_adminame;
  this.p_adminpwd = P_adminpwd;
  }
  }
 }

Sqlhelper类
namespace DLL
{
  public class SQLHelper
  {
  private SqlConnection conn = null;
  private SqlCommand cmd = null;
  private SqlDataReader sdr = null;
  public SQLHelper()
  {
  string c