📄 queryform.vb
字号:
Public Class QueryForm
Inherits System.Windows.Forms.Form
#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 Edit查询依据 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents CmbBox查询依据 As System.Windows.Forms.ComboBox
Friend WithEvents CmbBox排序依据 As System.Windows.Forms.ComboBox
Friend WithEvents CmbBox运算符 As System.Windows.Forms.ComboBox
Friend WithEvents Edit数值 As System.Windows.Forms.TextBox
Friend WithEvents Btn查询 As System.Windows.Forms.Button
Friend WithEvents Btn取消 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Edit查询依据 = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.CmbBox查询依据 = New System.Windows.Forms.ComboBox()
Me.CmbBox排序依据 = New System.Windows.Forms.ComboBox()
Me.CmbBox运算符 = New System.Windows.Forms.ComboBox()
Me.Edit数值 = New System.Windows.Forms.TextBox()
Me.Btn查询 = New System.Windows.Forms.Button()
Me.Btn取消 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(22, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(77, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "查询依据:"
'
'Edit查询依据
'
Me.Edit查询依据.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Edit查询依据.Location = New System.Drawing.Point(24, 64)
Me.Edit查询依据.Name = "Edit查询依据"
Me.Edit查询依据.Size = New System.Drawing.Size(72, 23)
Me.Edit查询依据.TabIndex = 1
Me.Edit查询依据.Text = ""
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.Location = New System.Drawing.Point(24, 112)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(77, 16)
Me.Label2.TabIndex = 2
Me.Label2.Text = "排序依据:"
'
'CmbBox查询依据
'
Me.CmbBox查询依据.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.CmbBox查询依据.Location = New System.Drawing.Point(120, 32)
Me.CmbBox查询依据.Name = "CmbBox查询依据"
Me.CmbBox查询依据.Size = New System.Drawing.Size(121, 22)
Me.CmbBox查询依据.TabIndex = 4
'
'CmbBox排序依据
'
Me.CmbBox排序依据.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.CmbBox排序依据.Location = New System.Drawing.Point(120, 104)
Me.CmbBox排序依据.Name = "CmbBox排序依据"
Me.CmbBox排序依据.Size = New System.Drawing.Size(121, 22)
Me.CmbBox排序依据.TabIndex = 5
'
'CmbBox运算符
'
Me.CmbBox运算符.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.CmbBox运算符.Items.AddRange(New Object() {">", ">=", "<", "<=", "=", "<>", "Like", "In"})
Me.CmbBox运算符.Location = New System.Drawing.Point(120, 64)
Me.CmbBox运算符.Name = "CmbBox运算符"
Me.CmbBox运算符.Size = New System.Drawing.Size(48, 22)
Me.CmbBox运算符.TabIndex = 6
'
'Edit数值
'
Me.Edit数值.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Edit数值.Location = New System.Drawing.Point(176, 64)
Me.Edit数值.Name = "Edit数值"
Me.Edit数值.Size = New System.Drawing.Size(64, 23)
Me.Edit数值.TabIndex = 7
Me.Edit数值.Text = ""
'
'Btn查询
'
Me.Btn查询.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Btn查询.Font = New System.Drawing.Font("宋体", 10.0!)
Me.Btn查询.Location = New System.Drawing.Point(24, 152)
Me.Btn查询.Name = "Btn查询"
Me.Btn查询.Size = New System.Drawing.Size(75, 24)
Me.Btn查询.TabIndex = 8
Me.Btn查询.Text = "查 询"
'
'Btn取消
'
Me.Btn取消.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Btn取消.Font = New System.Drawing.Font("宋体", 10.0!)
Me.Btn取消.Location = New System.Drawing.Point(168, 152)
Me.Btn取消.Name = "Btn取消"
Me.Btn取消.Size = New System.Drawing.Size(75, 24)
Me.Btn取消.TabIndex = 9
Me.Btn取消.Text = "取 消"
'
'QueryForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(272, 205)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Btn取消, Me.Btn查询, Me.Edit数值, Me.CmbBox运算符, Me.CmbBox排序依据, Me.CmbBox查询依据, Me.Label2, Me.Edit查询依据, Me.Label1})
Me.Name = "QueryForm"
Me.Text = "QueryForm"
Me.ResumeLayout(False)
End Sub
#End Region
Dim DataType(100) As Integer
Dim SqlString As String
Dim OrderString As String
Dim QueryString As String
Private Sub Btn查询_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn查询.Click
Select Case DataType(Me.CmbBox查询依据.SelectedIndex)
Case 1, 4, 5
SqlString = "SELECT * FROM 学生信息 INNER JOIN 原学历 ON 学生信息.学号 =原学历.学号 Where "
SqlString = SqlString + Me.Edit查询依据.Text + " " + Me.CmbBox运算符.Text + " " + "(" + Me.Edit数值.Text + ")"
Case 10
SqlString = "SELECT * FROM 学生信息 INNER JOIN 原学历 ON 学生信息.学号 =原学历.学号 Where "
SqlString = SqlString + Me.Edit查询依据.Text + " " + Me.CmbBox运算符.Text + " " + "'" + Me.Edit数值.Text + "'"
Case 8
SqlString = "SELECT * FROM 学生信息 INNER JOIN 原学历 ON 学生信息.学号 =原学历.学号 Where "
SqlString = SqlString + Me.Edit查询依据.Text + Me.CmbBox运算符.Text + "CDate(" + Me.Edit数值.Text + ")"
End Select
OrderString = Me.CmbBox排序依据.Text
QueryData(SqlString, OrderString)
End Sub
Sub QueryData(ByVal SqlString As String, ByVal OrderString As String)
QueryString = SqlString
If OrderString <> "" Then
QueryString = SqlString + " Order By " + OrderString
End If
TestRS = TestDB.OpenRecordset(QueryString)
End Sub
Private Sub QueryForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To TestRS.Fields.Count - 1
DataType(i) = TestRS.Fields(i).Type
Next
End Sub
Private Sub CmbBox查询依据_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbBox查询依据.SelectedIndexChanged
Me.Edit查询依据.Text = Me.CmbBox查询依据.Text
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -