⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmadduser.vb

📁 这是一个教务信息管理系统!
💻 VB
字号:
Imports System.Data
'引入数据库操作类命名空间
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
    '建立数据行对象
    Public rownumber As Integer
    '定义一个整型变量来存放当前行数
    Public SearchSQL As String
    Public cmd As OleDbCommandBuilder
#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    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 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    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 = "确认密码"
        '
        '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"
        '构造查询
        ExecuteSQL(SearchSQL, tablename) '调用查询函数
        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)
        '对数据库进行更新
        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对象
            '数据库查询函数
            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 '设置为第一行
            myrow = mytable.Rows.Item(rownumber)
            '取得第一行数据
        Catch
            MsgBox(Err.Description)
        End Try
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -