예제 #1
0
 /// <summary>
 /// 创建用户表单
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void createUser_Click(object sender, EventArgs e)
 {
     User user = new User();
     user.Pwd = Request["pwd"];
     if (user.Pwd.Equals(Request["pwdAgain"]))
     {
         Response.Write("<script>alert(\"两次输入的密码不同,请重新输入\")</script>");
     }
     user.UserName = Request["userName"];
     user.MailBox = Request["mailBox"];
     user.PhoneNumber = Request["phoneNumber"];
     UserDAO userDAO = new UserDAO();
     userDAO.insert(user);
     Response.Write("<script>alert(\"注册成功\")</script>");
     Response.Redirect("../Defalut.aspx");
 }
예제 #2
0
파일: UserDAO.cs 프로젝트: GUIZHOUET/ET03
 /// <summary>
 /// 将用户到插入到数据库
 /// </summary>
 public bool insert(User user)
 {
     string userName = user.UserName;
     string mailBox = user.MailBox;
     string pwd = user.Pwd;
     string phoneNumber = user.PhoneNumber;
     sqlconn.Open();//打开mysql的连接
     string sql = "INSERT INTO user(userName,mailBox,pwd,phoneNumber) VALUES (?userName,?mailBox,?pwd,?phoneNumber)";
     MySqlCommand cmd = new MySqlCommand(sql, sqlconn);
     MySqlParameter[] parameters = new MySqlParameter[4];
     parameters[0] = new MySqlParameter("?userName", MySqlDbType.VarChar);
     parameters[0].Value = userName;
     parameters[1] = new MySqlParameter("?mailBox", MySqlDbType.VarChar);
     parameters[1].Value = mailBox;
     parameters[2] = new MySqlParameter("?pwd", MySqlDbType.VarChar);
     parameters[2].Value = pwd;
     parameters[3] = new MySqlParameter("?phoneNumber", MySqlDbType.VarChar);
     parameters[3].Value = phoneNumber;
     cmd.Parameters.AddRange(parameters);
     cmd.ExecuteNonQuery();
     sqlconn.Close();
     return true;
 }