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