📄 ok查询老师.aspx.vb
字号:
Imports System.Data
Imports System.Data.SqlClient
Partial Class TeacherSearch_DB
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim strsql As String
Dim coon As New SqlConnection("Server=localhost;Database=选修课管理系统;Uid=sa;Pwd=;")
If (DropDownList1.SelectedItem.Text) = "教师编号" Then
strsql = "select 教师编号 from 老师表"
DropDownList2.DataTextField = "教师编号"
DropDownList2.DataValueField = "教师编号"
Else : strsql = "select 姓名 from 老师表"
DropDownList2.DataTextField = "姓名"
DropDownList2.DataValueField = "姓名"
End If
coon.Open()
Dim cmd1 As New SqlCommand(strsql, coon)
Dim dr1 As SqlDataReader = cmd1.ExecuteReader()
DropDownList2.DataSource = dr1
DropDownList2.DataBind()
coon.Close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strsql As String
Dim coon As New SqlConnection("Server=localhost;Database=选修课管理系统;Uid=sa;Pwd=;")
If (DropDownList1.SelectedItem.Text) = "教师编号" Then
strsql = "select * from 老师表 where 教师编号='" & DropDownList2.SelectedItem.Text & "' "
Else : strsql = "select * from 老师表 where 姓名='" & DropDownList2.SelectedItem.Text & "' "
End If
coon.Open()
Dim cmd1 As New SqlCommand(strsql, coon)
Dim dr1 As SqlDataReader = cmd1.ExecuteReader()
GridView1.DataSource = dr1
GridView1.DataBind()
coon.Close()
End Sub
Protected Sub DropDownList2_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.Init
Dim strsql2 As String
Dim coon As New SqlConnection("Server=localhost;Database=选修课管理系统;Uid=sa;Pwd=;")
strsql2 = "select 教师编号 from 老师表 "
coon.Open()
Dim cmd1 As New SqlCommand(strsql2, coon)
Dim dr1 As SqlDataReader = cmd1.ExecuteReader()
DropDownList2.DataTextField = "教师编号"
DropDownList2.DataValueField = "教师编号"
DropDownList2.DataSource = dr1
DropDownList2.DataBind()
'GridView1.DataSource = dr1
'GridView1.DataBind()
coon.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -