首页 > 数据库技术 > 详细

三层数据库四大法宝之“改”

时间:2015-02-06 11:18:28      阅读:308      评论:0      收藏:0      [点我收藏+]

    在改这个功能中我用到了两个窗体,一个用来获取原来的用户号,另一个用来获取现在的密码,下面我就来详细说明一下:

同样,实体层:

<span style="font-family:KaiTi_GB2312;font-size:24px;">''' <summary>
''' 实体层,存放多种属性
''' </summary>
''' <remarks></remarks>
Public Class User
    '定义UserName属性
    Private _UserName As String
    Public Property UserName As String
        Get
            Return _UserName
        End Get

        Set(value As String)
            _UserName = value
        End Set
    End Property

    '定义PassWord属性
    Private _PassWord As String '
    Public Property PassWord As String
        Get
            Return _PassWord
        End Get

        Set(value As String)
            _PassWord = value
        End Set
    End Property




End Class
</span>


UI层:

第一个窗体:

技术分享

<span style="font-family:KaiTi_GB2312;font-size:24px;">Public Class Form1
    '改
    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click
        frmChange.Show()                '调用改的窗体

    End Sub

End Class
</span>


第二个窗体:

技术分享

<span style="font-family:KaiTi_GB2312;font-size:24px;">Public Class frmChange

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnChange.Click
        Try
            '获得表现层的数据
            Dim nuser As New LoginMODEL.User              '实例化一个新的实体,用来传递B层的实体

            nuser.UserName = txtUserName.Text.Trim           '将用户名传递给实体层的UserName
            nuser.PassWord = txtPassWord.Text.Trim            '将密码传递给实体层的PassWord

            '调用B层,登录判断
            Dim mgr As New LoginBLL.UserMananger
            Call mgr.ChangeBLL(nuser)

        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())              '错误处理
        End Try
    End Sub
End Class</span>

BLL层:

<span style="font-family:KaiTi_GB2312;font-size:24px;">Public Class UserMananger
    '改

    Public Sub ChangeBLL(ByVal User As LoginMODEL.User)
        Dim uDAO As New LoginDAL.SqlserverUser

        '查询用户是否存在,如果存在修改密码,如果不存在提示框
        Dim mUser As LoginMODEL.User
        Call uDAO.ChangDAL(User)

        If IsNothing(mUser.UserName) Then
            MsgBox("用户不存在,请重新输入", , "警告")
        Else
            Call uDAO.ChangDAL(User)            '调用修改功能
        End If

    End Sub

End Class
</span>

<span style="background-color: rgb(255, 255, 255);"><span style="font-family:KaiTi_GB2312;font-size:24px;color:#3333ff;"><strong>DAL层:</strong></span></span>
<span style="background-color: rgb(255, 255, 255);"></span><pre name="code" class="vb"><span style="font-family:KaiTi_GB2312;font-size:24px;">' 引用命名空间
Imports System.Data
Imports System.Data.SqlClient
Imports LoginMODEL


Public Class SqlserverUser
    Public conn As New SqlConnection("server=ZY-PC;database=Login;user id=sa;password =1")          '创建数据库的连接

    '改
    Public Sub ChangDAL(ByVal User As User)

        Dim sql As String = "update T_Users set PassWord=@PassWord where UserName=@User"        '更新数库的SQL语句
        Dim cmd As New SqlCommand(sql, conn)
        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text
      
        cmd.Parameters.Add(New SqlParameter("@User", User.UserName))
        cmd.Parameters.Add(New SqlParameter("@PassWord", User.PassWord))
        conn.Open()
        cmd.ExecuteNonQuery()       '执行对数据库的操作
        conn.Close()
    End Sub

End Class</span>



三层数据库四大法宝之“改”

原文:http://blog.csdn.net/zygyl/article/details/43561075

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!