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

📄 admin.aspx.vb

📁 该学生信息管理系统是我自己写的
💻 VB
字号:
Imports System.Data
Imports System.Data.SqlClient
Imports System
Imports System.Collections
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.UI
Imports System.Text
Public Class Admin
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents FONT1 As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents DataGrid2 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents DataGrid3 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents DataGrid4 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents DataGrid5 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents DataGrid6 As System.Web.UI.WebControls.DataGrid

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If (Not IsPostBack) And (DropDownList1.SelectedItem.Text <> "请点下拉框") Then BindGrid() '在此处放置初始化页的用户代码
    End Sub
    Sub BindGrid()
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim DS As New DataSet

        conn.ConnectionString = "Data Source=MY-TOMATO;Initial Catalog=Student;User ID=sa;Password=sa"
        conn.Open()
        cmd.Connection = conn
        If DropDownList1.SelectedItem.Text = "student" Then
            cmd.CommandText = "Select studentname,studentID,class,sex from student"

        ElseIf DropDownList1.SelectedItem.Text = "course" Then
            cmd.CommandText = "Select coursename,cuorsetime,学分,teacher  from course"

        ElseIf DropDownList1.SelectedItem.Text = "score" Then
            cmd.CommandText = "Select studentID,coursename,grade,got_学分  from score"

        ElseIf DropDownList1.SelectedItem.Text = "admin" Then
            cmd.CommandText = "Select adminname,passwd  from admin"

        ElseIf DropDownList1.SelectedItem.Text = "users" Then
            cmd.CommandText = "Select Username,passwd from users"
        Else
            cmd.CommandText = "Select A.studentID,studentname,B.coursename,coursetime,grade,学分,got_学分 from student A,course B,score C where A.studentID=@studentID and A.studentID= C.studentID and B.coursename=C.coursename"
        End If


        Dim objAdpt As New SqlDataAdapter(cmd)


        If DropDownList1.SelectedItem.Text = "student" Then
            objAdpt.Fill(DS, "student")
            DataGrid1.DataSource = DS.Tables("student").DefaultView
            DataGrid1.DataBind()
        ElseIf DropDownList1.SelectedItem.Text = "course" Then
            objAdpt.Fill(DS, "course")
            DataGrid2.DataSource = DS.Tables("course").DefaultView
            DataGrid2.DataBind()
        ElseIf DropDownList1.SelectedItem.Text = "score" Then
            objAdpt.Fill(DS, "score")
            DataGrid3.DataSource = DS.Tables("score").DefaultView
            DataGrid3.DataBind()
        ElseIf DropDownList1.SelectedItem.Text = "admin" Then
            objAdpt.Fill(DS, "admin")
            DataGrid4.DataSource = DS.Tables("admin").DefaultView
            DataGrid4.DataBind()
        ElseIf DropDownList1.SelectedItem.Text = "users" Then
            objAdpt.Fill(DS, "users")
            DataGrid5.DataSource = DS.Tables("users").DefaultView
            DataGrid5.DataBind()
        Else
            objAdpt.Fill(DS, "student,course,score")
            DataGrid6.DataSource = DS.Tables("student,course,score").DefaultView
            DataGrid6.DataBind()
        End If

        conn.Close()
    End Sub
    Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
        DataGrid1.EditItemIndex = e.Item.ItemIndex
        BindGrid()
    End Sub
    Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
        DataGrid1.EditItemIndex = -1
        BindGrid()
    End Sub
    Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
        Dim TB As String
        Dim conn As New SqlConnection
        conn.ConnectionString = "Data Source=MY-TOMATO;Initial Catalog=Student;User ID=sa;Password=sa"
        Dim strSQL As String = "Update student Set studentID=@studentID,studentname=@studentname,class=@class,sex=@sex where studentID=@studentID"
        Dim cmd As New SqlCommand(strSQL, conn)


        cmd.Parameters.Add(New SqlParameter("@studentname", SqlDbType.VarChar, 10))
        cmd.Parameters.Add(New SqlParameter("@studentID", SqlDbType.VarChar, 10))
        cmd.Parameters.Add(New SqlParameter("@class", SqlDbType.VarChar, 10))
        cmd.Parameters.Add(New SqlParameter("@sex", SqlDbType.VarChar, 10))

        TB = e.Item.Cells(0).Text
        cmd.Parameters("@studentname").Value = TB

        TB = e.Item.Cells(1).Text
        cmd.Parameters("@studentID").Value = TB
        TB = e.Item.Cells(2).Text
        cmd.Parameters("@class").Value = TB

        TB = e.Item.Cells(3).Text
        cmd.Parameters("@sex").Value = TB

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        DataGrid1.EditItemIndex = -1
        BindGrid()
    End Sub
    Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
        Dim selected_id As Integer
        selected_id = e.Item.Cells(0).Text
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        conn.ConnectionString = "Data Source=MY-TOMATO;Initial Catalog=Student;User ID=sa;Password=sa"
        conn.Open()
        cmd.Connection = conn
        '形成Delete语句
        cmd.CommandText = "Delete From student Where studentID = " & selected_id
        cmd.ExecuteNonQuery()
        conn.Close()
        BindGrid()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If DropDownList1.SelectedItem.Text = "请点下拉框" Then
            DataGrid1.Visible = False
        Else
            DropDownList1.SelectedItem.Text = "student"
            DataGrid1.Visible = True
        End If
    End Sub

  
    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

    End Sub

    Private Sub DataGrid5_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid5.SelectedIndexChanged

    End Sub
End Class

⌨️ 快捷键说明

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