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

📄 frmaddresult.vb

📁 这是一个教务信息管理系统!
💻 VB
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class FrmAddResult
    Inherits System.Windows.Forms.Form
    Dim tablename As String = "result_Info"
    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 Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TxtDate As System.Windows.Forms.TextBox
    Friend WithEvents TxtSID As System.Windows.Forms.TextBox
    Friend WithEvents BtCancel As System.Windows.Forms.Button
    Friend WithEvents BtOK As System.Windows.Forms.Button
    Friend WithEvents TxtResult As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents TxtCourseno As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.TxtDate = New System.Windows.Forms.TextBox()
        Me.TxtResult = New System.Windows.Forms.TextBox()
        Me.TxtSID = New System.Windows.Forms.TextBox()
        Me.BtCancel = New System.Windows.Forms.Button()
        Me.BtOK = New System.Windows.Forms.Button()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.TxtCourseno = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        '
        '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, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(63, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.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(208, 16)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(34, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "学号"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label4.Location = New System.Drawing.Point(208, 56)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(34, 16)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "分数"
        '
        'TxtDate
        '
        Me.TxtDate.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.TxtDate.Location = New System.Drawing.Point(88, 16)
        Me.TxtDate.Name = "TxtDate"
        Me.TxtDate.Size = New System.Drawing.Size(88, 21)
        Me.TxtDate.TabIndex = 4
        Me.TxtDate.Text = ""
        '
        'TxtResult
        '
        Me.TxtResult.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.TxtResult.Location = New System.Drawing.Point(248, 56)
        Me.TxtResult.Name = "TxtResult"
        Me.TxtResult.Size = New System.Drawing.Size(104, 21)
        Me.TxtResult.TabIndex = 6
        Me.TxtResult.Text = ""
        '
        'TxtSID
        '
        Me.TxtSID.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.TxtSID.Location = New System.Drawing.Point(248, 16)
        Me.TxtSID.Name = "TxtSID"
        Me.TxtSID.Size = New System.Drawing.Size(104, 21)
        Me.TxtSID.TabIndex = 7
        Me.TxtSID.Text = ""
        '
        'BtCancel
        '
        Me.BtCancel.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.BtCancel.Location = New System.Drawing.Point(200, 96)
        Me.BtCancel.Name = "BtCancel"
        Me.BtCancel.Size = New System.Drawing.Size(96, 32)
        Me.BtCancel.TabIndex = 8
        Me.BtCancel.Text = "取消添加"
        '
        'BtOK
        '
        Me.BtOK.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.BtOK.Location = New System.Drawing.Point(56, 96)
        Me.BtOK.Name = "BtOK"
        Me.BtOK.Size = New System.Drawing.Size(96, 32)
        Me.BtOK.TabIndex = 9
        Me.BtOK.Text = "确认添加"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label5.Location = New System.Drawing.Point(16, 56)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(63, 16)
        Me.Label5.TabIndex = 15
        Me.Label5.Text = "课程编号"
        '
        'TxtCourseno
        '
        Me.TxtCourseno.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.TxtCourseno.Location = New System.Drawing.Point(88, 56)
        Me.TxtCourseno.Name = "TxtCourseno"
        Me.TxtCourseno.Size = New System.Drawing.Size(88, 21)
        Me.TxtCourseno.TabIndex = 14
        Me.TxtCourseno.Text = ""
        '
        'FrmAddResult
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(8, 16)
        Me.ClientSize = New System.Drawing.Size(376, 141)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.TxtCourseno, Me.BtOK, Me.BtCancel, Me.TxtSID, Me.TxtResult, Me.TxtDate, Me.Label4, Me.Label2, Me.Label1})
        Me.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Name = "FrmAddResult"
        Me.Text = "添加成绩信息"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click

        If Not IsNumeric(TxtCourseno.Text) Then
            MsgBox("请输入课程编号!", vbOKOnly + vbExclamation, "警告")
            TxtCourseno.Focus()
            Exit Sub
        End If


        If Not IsDate(TxtDate.Text) Then
            MsgBox("考试日期!", vbOKOnly + vbExclamation, "警告")
            TxtDate.Focus()
            Exit Sub
        End If



        If Not IsNumeric(TxtSID.Text) Then
            MsgBox("请输入学号", vbOKOnly + vbExclamation, "警告")
            TxtSID.Focus()
            Exit Sub
        End If
        If Not IsNumeric(TxtResult.Text) Then
            MsgBox("请输入分数", vbOKOnly + vbExclamation, "警告")
            TxtResult.Focus()
            Exit Sub
        End If
        SearchSQL = "select * from result_Info "
        ExecuteSQL(SearchSQL, tablename)


        Dim newrow As DataRow
        newrow = mytable.NewRow


        newrow.Item(1) = Trim(TxtDate.Text)
        newrow.Item(2) = Trim(TxtSID.Text)
        newrow.Item(3) = Trim(TxtCourseno.Text)
        newrow.Item(4) = Trim(TxtResult.Text)
        
        mytable.Rows.Add(newrow)
        cmd = New OleDbCommandBuilder(ADOcmd)
        '使用自动生成的SQL语句
        ADOcmd.Update(ds, tablename)
        '对数据库进行更新

        MsgBox("添加成绩信息成功!", vbOKOnly + vbExclamation, "警告")
        Me.Dispose()
    End Sub

    Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.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 + -