The "deletion" of the four key weapons of three-tier database

Source: Internet
Author: User
Tags error handling

The previous article introduced the "increase", this article to introduce the next magic Weapon-"delete"The physical layer is the same as the previous one, and there is not much to say here. U-Layer:
Public Class Form1    ' delete    Private Sub btndelete_click (sender as Object, e as EventArgs) Handles Btndelete.click        Try            ' Gets the data for the presentation layer            Dim Muser as new Loginmodel.user              ' instantiates a new entity that is used to pass a B-layer entity            Muser. UserName = TxtUserName.Text.Trim           ' passes the user name to the UserName Muser of the entity layer            . PassWord = TxtPassWord.Text.Trim            ' Pass the password to the entity layer PassWord            ' call layer B, login to determine            Dim Mgr as New Loginbll.usermananger Call            Mgr. DELETEBLL (Muser)        Catch ex as Exception            MessageBox.Show (ex. Message.tostring ())              ' Error handling        end Try    end Sub   End Class

b Layer:
' Delete public Class usermananger public    Sub DELETEBLL (ByVal User as Loginmodel.user)        Dim Udao as New logindal.sqlserve Ruser        ' query if the user exists, if there is a change password if there is no prompt box        Dim muser as loginmodel.user        muser = Udao.selectdal (User) if        IsNothing (muser.username)            then MsgBox ("User not present, re-enter", "warning")        Else call            udao.deletedal (user)   Call Delete function        end If    End SubEnd Class

Layer D:
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" > ' Referencing namespaces imports System.dataimports System.Data.SqlClientImports Loginmodel ' d layer, mainly for the raw data (database or text files, such as the form of data storage) operation layer, need to refer to the entity layer public Class Sqlserveruser public Conn as New SqlConnection (" Server=zy-pc;database=login;user Id=sa;password = 1 ") ' Create database connection ', delete public Sub deletedal (ByVal user as Use  R) ' Referencing an entity Dim SQL as String = "Delete from t_users where [email protected] and [email protected] "' Database DELETE statement Dim cmd as New SqlCommand (SQL, conn) cmd. CommandText = sql cmd. CommandType = CommandType.Text cmd. Parameters.Add (New SqlParameter ("@UserName", User.username)) ' assigns a value cmd to the variable @username. Parameters.Add (New SqlParameter ("@PassWord", User.password)) ' assigns Conn to @password. Open () cmd. ExecuteNonQuery () ' performs an operation on the database Conn. Close () end Sub End class</span> 



The "deletion" of the four key weapons of three-tier database

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.