sqllook.frm

来自「vb+mapx小型地图系统」· FRM 代码 · 共 196 行

FRM
196
字号
VERSION 5.00
Begin VB.Form sqlLook 
   Caption         =   "SQL查询"
   ClientHeight    =   4995
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4380
   Icon            =   "sqlLook.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4995
   ScaleWidth      =   4380
   StartUpPosition =   1  '所有者中心
   Begin VB.CommandButton Command2 
      Caption         =   "返回"
      Height          =   495
      Left            =   2640
      TabIndex        =   10
      Top             =   4320
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "确定"
      Height          =   495
      Left            =   720
      TabIndex        =   9
      Top             =   4320
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Caption         =   "条件设定"
      Height          =   2895
      Left            =   240
      TabIndex        =   2
      Top             =   1080
      Width           =   3855
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   1920
         TabIndex        =   6
         Top             =   2040
         Width           =   1575
      End
      Begin VB.ComboBox Combo3 
         Height          =   300
         Left            =   600
         TabIndex        =   4
         Top             =   2040
         Width           =   975
      End
      Begin VB.ComboBox Combo2 
         Height          =   300
         Left            =   1440
         TabIndex        =   3
         Top             =   600
         Width           =   1935
      End
      Begin VB.Label Label4 
         Caption         =   "输入数值:"
         Height          =   375
         Left            =   1920
         TabIndex        =   8
         Top             =   1560
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "选择条件:"
         Height          =   375
         Left            =   240
         TabIndex        =   7
         Top             =   1560
         Width           =   1095
      End
      Begin VB.Label Label2 
         Caption         =   "选择数字字段"
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   600
         Width           =   1095
      End
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   1680
      TabIndex        =   0
      Top             =   360
      Width           =   2295
   End
   Begin VB.Label Label1 
      Caption         =   "选择图层"
      Height          =   375
      Left            =   360
      TabIndex        =   1
      Top             =   360
      Width           =   975
   End
End
Attribute VB_Name = "sqlLook"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Combo1str As String
Dim Combo2str As String
Dim Combo3str As Integer
Dim rs1 As New ADODB.Recordset
Dim cnnstr As String

Private Sub Combo1_Click()
Set cnn = Nothing
Set rs = Nothing
Dim sqlstr As String
Combo2.Clear

Combo1str = Combo1.Text


cnnstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\mapdata\my.mdb;user id=admin;" & " password=;Persist Security Info=False"

cnn.ConnectionString = cnnstr
cnn.CursorLocation = adUseClient

cnn.Open
If cnn.State = adStateOpen Then

sqlstr = "select * from " & Combo1str
Set rs = cnn.Execute(sqlstr)
For i = 0 To rs.Fields.Count - 1
Combo2.AddItem rs.Fields(i).Name

Next i
Combo2.ListIndex = 0
Else
MsgBox "无法打开数据源或数据源不存在", 64, "信息提示"
End If

End Sub

Private Sub Command1_Click()
Dim tj As String
Dim sqlstr2 As String
Dim a As Double
a = Val(Text1.Text)
 Combo2str = Combo2.Text
 Combo3str = Combo3.ListIndex
 Select Case Combo3str
 Case Is = 0
 tj = ">"
 Case Is = 1
 tj = "="
 Case Else
 tj = "<"
 End Select
 
If IsNumeric(Text1.Text) = False Then
 MsgBox "请输入数字 ", 64, "信息提示"
Else
sqlstr2 = "select * from " & Combo1str & " where " & Combo2str & tj & a

Set rs1 = cnn.Execute(sqlstr2)
If rs1.EOF Then
 
 rs1.Close
 Set rs1 = Nothing
 
 MsgBox "无数据记录", 64, "提示"
Else
Set datashow.DataGrid1.DataSource = rs1
datashow.DataGrid1.Refresh
datashow.Show modal, Me

End If
End If
End Sub

Private Sub Command2_Click()
Set cnn = Nothing
Set rs = Nothing
Set rs1 = Nothing
Unload Me
End Sub

Private Sub Form_Load()

For Each look_lyr In mainform.Map1.Layers
      Combo1.AddItem look_lyr.Name
      Next
Combo3.AddItem ">"
Combo3.AddItem "="
Combo3.AddItem "<"
Combo3.ListIndex = 0

End Sub

⌨️ 快捷键说明

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