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