Three-storey architecture and four kings--change

Source: Internet
Author: User

Today, let's meet the last of the four Kings-- Modify the information in the database. Why do you put the changes after the query? This is because the need to modify the first to find out the information, so the query is the premise of the modification.

1. UI Layer

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

Then change the password "123456" to "5201314"

Verify that the modified code is as follows

[CSharp]View Plaincopy
  1. Private void button2_click (object sender, EventArgs e)
  2. {
  3. Login.Model.UserInfo user = new Login.Model.UserInfo (); //objects for transfer
  4. //Get the information you want to save
  5. User. UserName = TxtUserName.Text.Trim ();
  6. User. Password = txtPassword.Text;
  7. User. Email = Txtemail.text;
  8. //The object to be saved is handled by layer B
  9. UserModify.BLL2.ModifyBLL Modifyuserb = new UserModify.BLL2.ModifyBLL ();
  10. Modifyuserb.modify (user);
  11. MessageBox.Show ("Modify information successfully!  ");
  12. }
2. The BLL layer

[CSharp]View Plaincopy
  1. Public class MODIFYBLL
  2. {
  3. public void Modify (Login. Model. UserInfo user)
  4. {
  5. //Instantiate D layer
  6. UserModify.DAL2.ModifyDAL modifyuserd = new UserModify.DAL2.ModifyDAL ();
  7. //Data to be saved is saved by layer D
  8. Modifyuserd.modify (user);
  9. }
  10. }
3.DAL layer

[CSharp]View Plaincopy
  1. Public class Modifydal
  2. {
  3. public void Modify (Login.Model.UserInfo user)
  4. {
  5. using (SqlConnection conn=new SqlConnection (dbutil.connstring))
  6. {
  7. //Instantiate Command object
  8. SqlCommand cmd = conn. CreateCommand ();
  9. //Command Statements
  10. Cmd.commandtext = @"Update USERS SET [email protected],[email protected] WHERE [email protected]";
  11. Cmd.commandtype = CommandType.Text;
  12. //Pass the reference
  13. Cmd. Parameters.Add (new SqlParameter ("@password", user.  Password));
  14. Cmd. Parameters.Add (new SqlParameter ("@email", user.  Email));
  15. Cmd. Parameters.Add (new SqlParameter ("@userName", user.  UserName));
  16. //Open database connection
  17. Conn. Open ();
  18. //Modify Data
  19. Cmd. ExecuteNonQuery ();
  20. }
  21. }
  22. }
4. Results

5. Summary

At this point, we have introduced the "four Kings" completed. They have their own role in the database, there are sequencing, first let us look at the number of brothers ranked.

First, the eldest brother should be increased, only the first to add data, in order to have other operations, if there is no eldest brother, then the other few can only be an embroidered case a piece of trash, see not used, so the eldest is the top priority; the second dick should be a check, with the boss added data, you can have old and second query we want data Second, make our life easier and faster; Of course, if the data error, need to modify, the old three appearance, old three and the relationship between the second is very good, because old three need to help him find to modify the data, in order to play its talent, this will be brother concentric, its benefits of breaking gold; the last is the old four-delete, Old four can be arbitrarily deleted eldest brother added data, from this can see old four of the ability is not small, but he was brother several arrangements to the last, in the mind naturally is not convinced, not to mention it in addition to the eldest brother, but also secretly will the killer learned, and on its basis to improve, to detect all the records, This makes him more arrogant, but because eldest brother's prestige still not to belittle, so he can only seize the position of two elder brother, because the second really is skill inferior person, also can swallow. So the four brothers were later known as "increase, deletion, change, check." From then on, the four brothers worked together for our blessing.

This series of articles, for you to introduce the "increase, delete, change, check" the four brothers respective functions, so as to deepen our understanding of the three layer structure, we also found some problems, such as: Four brothers have a lot of similar places, so that the repetition of things will increase our burden, so predict funeral how, please see tell.

Three-storey architecture and four kings--change

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: 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.