?? frmmodifyuserpassword.vb
字號:
Imports System.Data
'引入數(shù)據(jù)庫操作類命名空間
Imports System.Data.OleDb
'引入ADO.NET操作命名空間
Public Class FrmModifyUserPassword
Inherits System.Windows.Forms.Form
Public tablename As String = "userID"
Public ADOcmd As OleDbDataAdapter
Public ds As DataSet = New DataSet()
'建立DataSet對象
Public mytable As Data.DataTable
'建立表單對象
Public myrow As Data.DataRow
'建立數(shù)據(jù)行對象
Public rownumber As Integer
'定義一個整型變量來存放當前行數(shù)
Public SearchSQL As String
Public cmd As OleDbCommandBuilder
#Region " Windows 窗體設(shè)計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調(diào)用是 Windows 窗體設(shè)計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調(diào)用之后添加任何初始化
End Sub
'窗體重寫處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設(shè)計器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下過程是 Windows 窗體設(shè)計器所必需的
'可以使用 Windows 窗體設(shè)計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TxtUserPassword As System.Windows.Forms.TextBox
Friend WithEvents TxtUserName As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TxtNewPassword As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.TxtUserPassword = New System.Windows.Forms.TextBox()
Me.TxtUserName = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.TxtNewPassword = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Button2
'
Me.Button2.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.Location = New System.Drawing.Point(16, 128)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 32)
Me.Button2.TabIndex = 12
Me.Button2.Text = "確定"
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Location = New System.Drawing.Point(112, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 32)
Me.Button1.TabIndex = 11
Me.Button1.Text = "取消"
'
'TxtUserPassword
'
Me.TxtUserPassword.Location = New System.Drawing.Point(96, 48)
Me.TxtUserPassword.Name = "TxtUserPassword"
Me.TxtUserPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TxtUserPassword.TabIndex = 10
Me.TxtUserPassword.Text = ""
'
'TxtUserName
'
Me.TxtUserName.Location = New System.Drawing.Point(96, 16)
Me.TxtUserName.Name = "TxtUserName"
Me.TxtUserName.TabIndex = 9
Me.TxtUserName.Text = ""
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label3.Location = New System.Drawing.Point(8, 48)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(34, 16)
Me.Label3.TabIndex = 8
Me.Label3.Text = "密碼"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.Location = New System.Drawing.Point(8, 16)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(49, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = "用戶名"
'
'TxtNewPassword
'
Me.TxtNewPassword.Location = New System.Drawing.Point(96, 80)
Me.TxtNewPassword.Name = "TxtNewPassword"
Me.TxtNewPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TxtNewPassword.TabIndex = 14
Me.TxtNewPassword.Text = ""
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 80)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(49, 16)
Me.Label1.TabIndex = 13
Me.Label1.Text = "新密碼"
'
'FrmModifyUserPassword
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(216, 165)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TxtNewPassword, Me.Label1, Me.Button2, Me.Button1, Me.TxtUserPassword, Me.TxtUserName, Me.Label3, Me.Label2})
Me.Name = "FrmModifyUserPassword"
Me.Text = "修改密碼"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim tablename As String
tablename = "userID" '表的名稱
SearchSQL = "SELECT 用戶名, 密碼 FROM userID WHERE (用戶名 = '" & TxtUserName.Text & " ') "
Try
ExecuteSQL(SearchSQL, tablename) '查詢函數(shù)
If myrow.Item(1) = TxtUserPassword.Text Then '比較輸入密碼和數(shù)據(jù)庫的密碼
myrow.Item(1) = TxtNewPassword.Text
mytable.GetChanges()
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自動生成的SQL語句
ADOcmd.Update(ds, tablename)
'對數(shù)據(jù)庫進行更新
MsgBox("密碼修改成功!", vbOKOnly + vbExclamation, "警告")
Me.Hide()
Else
Exit Sub
End If
Catch
MsgBox("沒有該用戶", vbOKOnly + vbExclamation, "警告")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Dispose()
End Sub
Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)
Try
'建立ADODataSetCommand對象
'數(shù)據(jù)庫查詢函數(shù)
ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\student.mdb")
'建立ADODataSetCommand對象
ADOcmd.Fill(ds, table) '取得表單
mytable = ds.Tables.Item(0) '取得名為table的表
rownumber = 0 '設(shè)置為第一行
myrow = mytable.Rows.Item(rownumber)
'取得第一行數(shù)據(jù)
Catch
MsgBox(Err.Description)
End Try
End Function
End Class
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -