📄 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 CmbBox查询依据 As System.Windows.Forms.ComboBox
Friend WithEvents CmbBox排序依据 As System.Windows.Forms.ComboBox
Friend WithEvents CmbBox运算符 As System.Windows.Forms.ComboBox
Friend WithEvents Btn取消 As System.Windows.Forms.Button
Friend WithEvents Btn确定 As System.Windows.Forms.Button
Friend WithEvents CmbBox查询表 As System.Windows.Forms.ComboBox
Friend WithEvents Label查询依据 As System.Windows.Forms.Label
Friend WithEvents Label排序依据 As System.Windows.Forms.Label
Friend WithEvents Edit指定值 As System.Windows.Forms.TextBox
Friend WithEvents Label运算符 As System.Windows.Forms.Label
Friend WithEvents Label指定值 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label查询依据 = New System.Windows.Forms.Label()
Me.Label排序依据 = 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.Label运算符 = New System.Windows.Forms.Label()
Me.Label指定值 = New System.Windows.Forms.Label()
Me.CmbBox查询表 = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'Label查询依据
'
Me.Label查询依据.AutoSize = True
Me.Label查询依据.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label查询依据.Location = New System.Drawing.Point(8, 16)
Me.Label查询依据.Name = "Label查询依据"
Me.Label查询依据.Size = New System.Drawing.Size(77, 16)
Me.Label查询依据.TabIndex = 0
Me.Label查询依据.Text = "查询依据:"
'
'Label排序依据
'
Me.Label排序依据.AutoSize = True
Me.Label排序依据.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label排序依据.Location = New System.Drawing.Point(8, 112)
Me.Label排序依据.Name = "Label排序依据"
Me.Label排序依据.Size = New System.Drawing.Size(77, 16)
Me.Label排序依据.TabIndex = 2
Me.Label排序依据.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(8, 64)
Me.CmbBox查询依据.Name = "CmbBox查询依据"
Me.CmbBox查询依据.Size = New System.Drawing.Size(104, 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(120, 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(27, 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(160, 152)
Me.Btn取消.Name = "Btn取消"
Me.Btn取消.Size = New System.Drawing.Size(75, 24)
Me.Btn取消.TabIndex = 9
Me.Btn取消.Text = "取 消"
'
'Label运算符
'
Me.Label运算符.AutoSize = True
Me.Label运算符.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label运算符.Location = New System.Drawing.Point(119, 40)
Me.Label运算符.Name = "Label运算符"
Me.Label运算符.Size = New System.Drawing.Size(63, 16)
Me.Label运算符.TabIndex = 10
Me.Label运算符.Text = "运算符:"
'
'Label指定值
'
Me.Label指定值.AutoSize = True
Me.Label指定值.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label指定值.Location = New System.Drawing.Point(177, 40)
Me.Label指定值.Name = "Label指定值"
Me.Label指定值.Size = New System.Drawing.Size(63, 16)
Me.Label指定值.TabIndex = 11
Me.Label指定值.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(8, 40)
Me.CmbBox查询表.Name = "CmbBox查询表"
Me.CmbBox查询表.Size = New System.Drawing.Size(104, 22)
Me.CmbBox查询表.TabIndex = 12
'
'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.CmbBox查询表, Me.Label指定值, Me.Label运算符, Me.Btn取消, Me.Btn确定, Me.Edit指定值, Me.CmbBox运算符, Me.CmbBox排序依据, Me.CmbBox查询依据, Me.Label排序依据, Me.Label查询依据})
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
Dim TempRS As ADODB.Recordset = New ADODB.Recordset()
Public Query编号 As Integer
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, 3, 4, 5
SqlString = "SELECT * FROM " + Me.CmbBox查询表.Text + " Where "
SqlString = SqlString + Me.CmbBox查询依据.Text + " " + Me.CmbBox运算符.Text + " " + "(" + Me.Edit指定值.Text + ")"
Case 10, 202
SqlString = "SELECT * FROM " + Me.CmbBox查询表.Text + " Where "
SqlString = SqlString + Me.CmbBox查询依据.Text + " " + Me.CmbBox运算符.Text + " " + "'" + Me.Edit指定值.Text + "'"
Case 8, 7
SqlString = "SELECT * FROM " + Me.CmbBox查询表.Text + " Where "
SqlString = SqlString + Me.CmbBox查询依据.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
If TempRS.State <> ADODB.ObjectStateEnum.adStateClosed Then
TempRS.Close()
End If
TempRS.Open(QueryString, MyCnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
TempRS.MoveFirst()
If TempRS.RecordCount < 1 Then
MsgBox("对不起,没有相应的记录")
Exit Sub
End If
MyRs.MoveFirst()
Dim i As Integer = 0
Do While Not MyRs.EOF
If MyRs.Fields("编号").Value.ToString = TempRS.Fields("编号").Value.ToString Then
MsgBox("找到了记录")
Me.Query编号 = i
End If
MyRs.MoveNext()
i = i + 1
Loop
If TempRS.State <> ADODB.ObjectStateEnum.adStateClosed Then
TempRS.Close()
End If
TempRS.Open(QueryString, MyCnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
End Sub
Private Sub QueryForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CmbBox查询表.Items.Add("奖惩")
Me.CmbBox查询表.Items.Add("联系方式")
Me.CmbBox查询表.Items.Add("人事变动")
Me.CmbBox查询表.Items.Add("学业")
Me.CmbBox查询表.Items.Add("职工信息")
Me.CmbBox查询表.SelectedIndex = 0
Me.Query编号 = 0
End Sub
Private Sub CmbBox查询表_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbBox查询表.SelectedIndexChanged
If TempRS.State <> ADODB.ObjectStateEnum.adStateClosed Then
TempRS.Close()
End If
TempRS.Open("Select * From " + Me.CmbBox查询表.SelectedItem + " Order By 编号", MyCnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
Me.CmbBox查询依据.Items.Clear()
Me.CmbBox排序依据.Items.Clear()
Dim i As Integer
For i = 0 To TempRS.Fields.Count - 1
DataType(i) = TempRS.Fields(i).Type
Me.CmbBox查询依据.Items.Add(TempRS.Fields(i).Name)
Me.CmbBox排序依据.Items.Add(TempRS.Fields(i).Name)
Next
Me.CmbBox查询依据.SelectedIndex = 0
Me.CmbBox排序依据.SelectedIndex = 0
End Sub
Private Sub QueryForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
TempRS.Close()
TempRS = Nothing
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -