📄 查询.vb
字号:
Imports System.Data.SqlClient
Public Class 查询
Inherits System.Windows.Forms.Form
Dim sqlstr As String
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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 DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button3 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(0, 0)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(352, 192)
Me.DataGrid1.TabIndex = 0
'
'GroupBox1
'
Me.GroupBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.GroupBox1.Controls.Add(Me.Button3)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.TextBox3)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.TextBox2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Location = New System.Drawing.Point(0, 208)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(352, 152)
Me.GroupBox1.TabIndex = 8
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "请输入查询条件:"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(280, 111)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(56, 23)
Me.Button3.TabIndex = 17
Me.Button3.Text = "查询"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(40, 118)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(104, 16)
Me.Label1.TabIndex = 16
Me.Label1.Text = "按专业查询查询:"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(144, 113)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(120, 21)
Me.TextBox3.TabIndex = 15
Me.TextBox3.Text = ""
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(280, 68)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 23)
Me.Button2.TabIndex = 14
Me.Button2.Text = "查询"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 75)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 16)
Me.Label3.TabIndex = 13
Me.Label3.Text = "按电话号码查询查询:"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(144, 70)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(120, 21)
Me.TextBox2.TabIndex = 12
Me.TextBox2.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(280, 25)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 23)
Me.Button1.TabIndex = 11
Me.Button1.Text = "查询"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(40, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(104, 16)
Me.Label2.TabIndex = 10
Me.Label2.Text = "按宿舍编号查询:"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(144, 27)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(120, 21)
Me.TextBox1.TabIndex = 9
Me.TextBox1.Text = ""
'
'查询
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(352, 359)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "查询"
Me.Text = "查询"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
'---------按房间编号查询--------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sqlstr = "select * from 人员管理 where 房间id='" & TextBox1.Text & "'"
Dim mycom As New SqlCommand(sqlstr, mycon)
mycon.Open()
mycom.ExecuteNonQuery()
mycon.Close()
dbbd()
End Sub
#Region "数据绑定代码,配合修改按钮实现,这是采用了前面的宿舍管理那一套东西"
Sub dbbd()
Dim myt As New DataTable
Dim myad As New SqlDataAdapter(sqlstr, mycon)
mycon.Open()
myad.Fill(myt)
mycon.Close()
DataGrid1.DataSource = myt
'btt_xg.Enabled = False
'btt_del.Enabled = False
End Sub
#End Region
'------------按电话查询----------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
sqlstr = "select * from 宿舍管理 where 宿舍电话='" & TextBox2.Text & "'"
Dim mycom As New SqlCommand(sqlstr, mycon)
mycon.Open()
mycom.ExecuteNonQuery()
mycon.Close()
dbbd()
End Sub
'----------按专业查询---------
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
sqlstr = "select * from 人员管理 where 专业='" & TextBox3.Text & "'"
Dim mycom As New SqlCommand(sqlstr, mycon)
mycon.Open()
mycom.ExecuteNonQuery()
mycon.Close()
dbbd()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -