Three-tier database "Check" four magic weapon

Source: Internet
Author: User

After completing these four functions feel "check" is the most simple of the four functions, the following to see how it is implemented:

The physical layer is not said to be the same as the first three functions.

UI layer:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" >public Class Form1    ' query    Private Sub btnlogin_click (sender as Object, e as EventArgs) Handles btnselect.click
   try            ' Gets the data for the presentation layer            Dim Muser as new Loginmodel.user              ' instantiates a new entity to pass the entity muser of Layer B            . 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.SELECTBLL            Muser = Mgr. SELECTBLL (Muser)        Catch ex as Exception            MessageBox.Show (ex. Message.tostring ())              ' Error handling        end Try    end Sub   End class</span>

BLL layer:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" > SELECTBLL public    Function SELECTBLL (ByVal User as Loginmodel.user) as Loginmodel.user        Dim Udao as New Logindal.sqlserveruser ()               ' instantiates a new Userdao object in the D layer        Dim Muser as Loginmodel.user                  ' defines a type as the entity layer parameter, the user assigns the value        Muser = Udao.selectdal (User)        ' determines whether to query to record        if IsNothing (muser.username) then            Throw New Exception ("Query failed , please check your username and password! ")          ' did not record        Else            MsgBox (" The query succeeded, congratulations! "," cue box ")         ' has a record        end If        return Muser            ' returns the entity    end FunctionEnd class</span>

dal layer:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" > ' Referencing namespaces imports System.dataimports System.Data.SqlClientImports Loginmodel ' d layer, mainly on the original data (database or text files, such as the form of data storage) operation layer, need to refer to the physical layer ' public Class sqlserveruser public Conn as New SqlConnection (" Server=zy-pc;database=login;user Id=sa;password = 1 ") ' Create database connection public Function Selectdal (ByVal user as user) A        S loginmodel.user ' transfer entity login for easy invocation of parameters in entities Dim reader as SqlDataReader ' defines variable reader of type SqlDataReader Dim Muser As New Loginmodel.user Dim sql As String = "Select Username,password from T_users where [Email&nbs        P;protected] and [email protected] "database query statement Dim cmd as New SqlCommand (SQL, conn) ' Create SqlCommand Object Cmd. CommandText = SQL ' gets the concrete content of the SQL statement cmd. CommandType = CommandType.Text ' Gets the specific type of the above SQL statement, CMD. Parameters.Add (New SqlParameter ("@UserName", User.username)) cmd. Parameters.Add (New SqlParameter ("@PassWord", User.password)) Conn. Open () ' opens data connection reader = cmd. ExecuteReader () ' Executes the query statement and generates a DataReader ' read the query to the data and returns it to the corresponding property while reader. Read () Muser.username = reader. GetString ("UserName") ' assigns value to @username Muser.password = reader. GetString ("PassWord") ' assigns an End while return Muser ' to @password to return the entity conn to the query. Close () ' Closed connection End functionend class</span>


database Four magic weapons to this has all been introduced, of course, this is a three-tier database "natural to carve" the most basic, the most simple, but also need to undergo further processing and improvement.


Three-tier database "Check" four magic weapon

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.