?? frmadduser.vb
字號:
Imports System.Data
'引入數(shù)據(jù)庫操作類命名空間
Imports System.Data.OleDb
'引入ADO.NET操作命名空間
Public Class FrmAddUser
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
'定義一個整型變量來存放當(dāng)前行數(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 TxtComfirmPassword 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.TxtComfirmPassword = 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(24, 120)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 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, 120)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 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(16, 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(16, 16)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(49, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = "用戶名"
'
'TxtComfirmPassword
'
Me.TxtComfirmPassword.Location = New System.Drawing.Point(96, 80)
Me.TxtComfirmPassword.Name = "TxtComfirmPassword"
Me.TxtComfirmPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TxtComfirmPassword.TabIndex = 14
Me.TxtComfirmPassword.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(16, 80)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(63, 16)
Me.Label1.TabIndex = 13
Me.Label1.Text = "確認(rèn)密碼"
'
'FrmAddUser
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(224, 165)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TxtComfirmPassword, Me.Label1, Me.Button2, Me.Button1, Me.TxtUserPassword, Me.TxtUserName, Me.Label3, Me.Label2})
Me.Name = "FrmAddUser"
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
If TxtUserPassword.Text <> TxtComfirmPassword.Text Then
MsgBox("前后兩次輸入的密碼不一致" + Chr(10) + "請重試", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
SearchSQL = "SELECT * FROM userID"
'構(gòu)造查詢
ExecuteSQL(SearchSQL, tablename) '調(diào)用查詢函數(shù)
Dim newrow As DataRow
newrow = mytable.NewRow
newrow.Item(0) = Trim(TxtUserName.Text) '給第一個字段賦值
newrow.Item(1) = Trim(TxtUserPassword.Text) '給第二個字段賦值
mytable.Rows.Add(newrow) '添加新用戶
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自動生成的SQL語句
ADOcmd.Update(ds, tablename)
'對數(shù)據(jù)庫進(jìn)行更新
MsgBox("添加用戶成功!", vbOKOnly + vbExclamation, "信息框")
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 + -