Three-tier architecture and four major Kings-change

Source: Internet
Author: User

Today, let's take a look at the last one in the "Four Kings"-modifying information in the database. Why should we put the changes after the query? This is because the information must be checked out before modification, so the query is the prerequisite for modification.

1. UI Layer

First, query the records to be modified, such as "Faye Wong" (for the code, see the previous article)


Change the password "123456" to "5201314"


The modified code is as follows:

Private void button2_click (Object sender, eventargs e) {login. model. userinfo user = New login. model. userinfo (); // The object used for transmission // get the information to save user. username = txtusername. text. trim (); User. password = txtpassword. text; user. email = txtemail. text; // the object to be saved is passed to layer B to process usermodify. bll2.modifybll modifyuserb = new usermodify. bll2.modifybll (); modifyuserb. modify (User); MessageBox. show ("Information modified successfully! ");}

2. BLL Layer

Public class modifybll {public void modify (login. model. userinfo user) {// instantiate layer D usermodify. dal2.modifydal modifyuserd = new usermodify. dal2.modifydal (); // The data to be saved is stored in modifyuserd by layer D. modify (User );}}
3. Dal Layer

Public class modifydal {public void modify (login. model. userinfo user) {using (sqlconnection conn = new sqlconnection (dbutil. connstring) {// instantiate the command object sqlcommand cmd = Conn. createcommand (); // command statement cmd. commandtext = @ "Update users set [email protected], [email protected] Where [email protected]"; cmd. commandtype = commandtype. text; // specify the CMD parameter. parameters. add (New sqlparameter ("@ password", user. password); cmd. parameters. add (New sqlparameter ("@ email", user. email); cmd. parameters. add (New sqlparameter ("@ username", user. username); // open the database connection Conn. open (); // modify the data cmd. executenonquery ();}}}

4. Results


5. Summary

Now, we have introduced the Four Kings. They have their respective roles and order for the database. Let's take a look at the rankings of the brothers first.

First, the boss should be increasing. Only by adding data first can there be other operations. If there is no boss, the other few can only be embroidered pillows and grass bags, so the boss is the top priority; second, we should check the data that the boss has added. Second, we can query the data we want. Second, we can make our life more convenient. Of course, if the data goes wrong and needs to be modified, it is time for the old Three to appear. The relationship between the old Three and the second two is very good, because the old Three needs to help him find the data to be modified before he can make full use of his talents, this requires brokers to work with each other, and the last part is the old four-delete. The old four can delete the data added by the old four at will. From this, we can see that the old four are not small, however, when he was finally arranged by his brother, his heart was naturally not convinced. What's more, in addition to being able to compete with the boss, he also secretly learned the killer of his second brother and made improvements based on it, he was able to find out all the records, which made him more arrogant. However, because of the prestige of his eldest brother, he could only take up the position of his second brother. Because the second brother is really not skilled, you can only swallow your breath. Therefore, the four brothers are called "add, delete, modify, and query" by future generations ". Since then, the four brothers have worked together to benefit us.

This series of articles introduces the functions of the four brothers "add, delete, modify, and query", so as to deepen our understanding of the three-tier architecture, from which we also find some problems, such: there are many similarities among the four brothers. Repeated things will increase the burden on us, so please refer to the next decomposition to predict the future.




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.