Asp. NET User registration (11th section) _ Practical skills

Source: Internet
Author: User

In our section four---asp.net implementation of user registration and validation functions, has learned the ASP.net validation control the role and use of methods, so relatively easy to this.
Learning content:
step by adding a new item, creating a Web Form and naming it "zhuce.aspx"
Step two layout page, create a table with 6 rows 2 columns

Step three writes the code in the Zhucechuli.cs page as follows:

public class Zhucechuli
 {public Zhucechuli ()
  {
  }
  private SqlConnection conn;
   public static void Addzhuce (Zhuce zhuce1)
   {using (SqlConnection cn = dbconn. Getconnection ())
   {CN. Open ();
    SqlCommand cm = new SqlCommand ();
    Cm. Connection = cn;
    String sql = "Insert Zhuce (Yhm,yhpwd,sex,hobby) VALUES (@q,@w,@e,@r)";
    Cm.commandtext = SQL;
    Cm. Parameters.addwithvalue ("@q", Zhuce1. YHM);
    Cm. Parameters.addwithvalue ("@w", Zhuce1. YHPWD);
    Cm. Parameters.addwithvalue ("@e", Zhuce1. SEX);
    Cm. Parameters.addwithvalue ("@r", Zhuce1. Hobby);
    Cm. ExecuteNonQuery ();}}

Step four Add the Zhuce class under the Entity class folder. Write the code in the page as follows:

Namespace Shiti
{
 ///<summary>
 ///zhuce Summary description
 ///</summary> public
 class Zhuce
 {public zhuce ()
  {
   }
  protected int id;
  public int ID
  {get
   {return id;}
   set {id = value;}
  }
  protected string yhm;
  public string Yhm
  {get
   {return yhm;}
   set {YHM = value;}
  }
  protected string yhpwd;
  public string yhpwd
  {get
   {return yhpwd;}
   set {yhpwd = value;}
  }
 protected string sex;
  public string Sex
  {get
   {return Sex;}
   set {sex = value;}
  }
protected string Hobby;
  public string Hobby
  {get
   {return Hobby;}
   set {hobby= value;}}}}

Step five Open the Zhuce.aspx design page and double-click the Button1 button to write code:

protected void Button1_Click (object sender, EventArgs e)
 {
  zhuce = null;
  Zhuce1 = new Zhuce ();
  Zhuce1. YHM = TextBox1.Text.ToString (). Trim ();
  Zhuce1. Yhpwd = TextBox2.Text.ToString (). Trim ();
  Zhuce1. Sex = DropDownList1.SelectedValue.ToString (). Trim ();
  Zhuce1. Hobby = DropDownList2.SelectedValue.ToString (). Trim ();
  Zhucechuli.addzhuce (Zhuce1); 
}

To add a little bit here, because this is learning asp.net, so the database content is not involved, the following is my asp.net when learning the configuration of the database part of the content:

If you want to know more about the content of the database, go to the website to focus on the database column, the content is also very rich.

Run Effect chart:

Summarize
Through this section of learning, to achieve the user's registration, further improve the content of the previous study, the realization of the foreground and database backstage connection, Small series of asp.net 11 learning summary, are their own hands-on and recorded the study notes, may be some places are not meticulous, the expression is not accurate, I hope you understand ha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.