📄 selecttrain.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form form3
Caption = "查询窗口"
ClientHeight = 7590
ClientLeft = 60
ClientTop = 405
ClientWidth = 8565
LinkTopic = "Form3"
ScaleHeight = 7590
ScaleWidth = 8565
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame3
Caption = "查询所有车次"
Height = 975
Left = 720
TabIndex = 12
Top = 6480
Width = 4095
Begin VB.CommandButton Command4
Caption = "查询"
Height = 495
Left = 1200
TabIndex = 13
Top = 240
Width = 1215
End
End
Begin VB.CommandButton Command1
Caption = "退出"
Height = 495
Left = 5760
TabIndex = 11
Top = 5280
Width = 1215
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 2535
Left = 720
TabIndex = 10
Top = 240
Width = 6855
_ExtentX = 12091
_ExtentY = 4471
_Version = 393216
Cols = 7
FixedCols = 0
GridLines = 2
AllowUserResizing= 1
End
Begin VB.Frame Frame2
Caption = "按车次查询:"
Height = 1215
Left = 720
TabIndex = 1
Top = 4920
Width = 4095
Begin VB.CommandButton Command3
Caption = "查询"
Height = 495
Left = 2400
TabIndex = 9
Top = 360
Width = 975
End
Begin VB.TextBox Text4
Height = 495
Left = 840
TabIndex = 8
Top = 360
Width = 1095
End
Begin VB.Label Label4
Caption = "车次:"
Height = 375
Left = 240
TabIndex = 7
Top = 480
Width = 735
End
End
Begin VB.Frame Frame1
Caption = "按站查询:"
Height = 1575
Left = 720
TabIndex = 0
Top = 3120
Width = 6135
Begin VB.CommandButton Command2
Caption = "查询"
Height = 495
Left = 4800
TabIndex = 6
Top = 480
Width = 975
End
Begin VB.TextBox Text3
Height = 495
Left = 3240
TabIndex = 5
Top = 480
Width = 1215
End
Begin VB.TextBox Text2
Height = 495
Left = 960
TabIndex = 3
Top = 480
Width = 1095
End
Begin VB.Label Label1
Caption = "终点站:"
Height = 495
Left = 2400
TabIndex = 4
Top = 480
Width = 975
End
Begin VB.Label Label2
Caption = "始点站:"
Height = 495
Left = 240
TabIndex = 2
Top = 600
Width = 975
End
End
End
Attribute VB_Name = "form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim conn As New ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmd As New ADODB.Command
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Command2_Click()
Form_Load
Dim rst1 As ADODB.Recordset
Dim textSQL As String
textSQL = "select * from trainticket where 始点站='" & Text2.Text & "'" & "and 终点站='" & Text3.Text & "'"
Set rst1 = New ADODB.Recordset
rst1.Open Trim$(textSQL), conn '用存储过程代替,不能显示
If rst1.State = 1 Then
With MSFlexGrid1
.Cols = 7
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "车次"
.TextMatrix(1, 1) = "始点站"
.TextMatrix(1, 2) = "终点站"
.TextMatrix(1, 3) = "列车类型"
.TextMatrix(1, 4) = "出发时间"
.TextMatrix(1, 5) = "到达时间"
.TextMatrix(1, 6) = "乘车时间"
While rst1.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst1.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst1.Fields(1)
.TextMatrix(.Rows - 1, 2) = rst1.Fields(2)
.TextMatrix(.Rows - 1, 3) = rst1.Fields(3)
.TextMatrix(.Rows - 1, 4) = rst1.Fields(4)
.TextMatrix(.Rows - 1, 5) = rst1.Fields(5)
.TextMatrix(.Rows - 1, 6) = rst1.Fields(6)
rst1.MoveNext
Wend
End With
rst1.Close
conn.Close
End If
End Sub
Private Sub Command3_Click()
Form_Load
Dim rst1 As New ADODB.Recordset
'Dim textSQL As String'
'textSQL = "select * from trainticket where 车次='" & Text4.Text & "'"'
'Set rst = New ADODB.Recordset'
'rst.Open Trim$(textSQL), conn'
Set rst1 = conn.Execute("exec selectticket '" & Text4.Text & "'")
If rst1.State = 1 Then
With MSFlexGrid1
.Cols = 7
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "车次"
.TextMatrix(1, 1) = "始点站"
.TextMatrix(1, 2) = "终点站"
.TextMatrix(1, 3) = "列车类型"
.TextMatrix(1, 4) = "出发时间"
.TextMatrix(1, 5) = "到达时间"
.TextMatrix(1, 6) = "乘车时间"
While rst1.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = rst1.Fields(0)
.TextMatrix(.Rows - 1, 1) = rst1.Fields(1)
.TextMatrix(.Rows - 1, 2) = rst1.Fields(2)
.TextMatrix(.Rows - 1, 3) = rst1.Fields(3)
.TextMatrix(.Rows - 1, 4) = rst1.Fields(4)
.TextMatrix(.Rows - 1, 5) = rst1.Fields(5)
.TextMatrix(.Rows - 1, 6) = rst1.Fields(6)
rst1.MoveNext
Wend
End With
rst1.Close
conn.Close
End If
End Sub
Private Sub Command4_Click()
Form_Load
Dim textSQL As String
Dim RST2 As ADODB.Recordset
textSQL = "select * from trainticket"
Set RST2 = New ADODB.Recordset
RST2.Open Trim$(textSQL), conn
If RST2.State = 1 Then
With MSFlexGrid1
.Cols = 7
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "车次"
.TextMatrix(1, 1) = "始点站"
.TextMatrix(1, 2) = "终点站"
.TextMatrix(1, 3) = "列车类型"
.TextMatrix(1, 4) = "出发时间"
.TextMatrix(1, 5) = "到达时间"
.TextMatrix(1, 6) = "乘车时间"
While RST2.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = RST2.Fields(0)
.TextMatrix(.Rows - 1, 1) = RST2.Fields(1)
.TextMatrix(.Rows - 1, 2) = RST2.Fields(2)
.TextMatrix(.Rows - 1, 3) = RST2.Fields(3)
.TextMatrix(.Rows - 1, 4) = RST2.Fields(4)
.TextMatrix(.Rows - 1, 5) = RST2.Fields(5)
.TextMatrix(.Rows - 1, 6) = RST2.Fields(6)
RST2.MoveNext
Wend
End With
RST2.Close
conn.Close
End If
End Sub
Private Sub Form_Load()
Dim ConnectString As String
Set conn = New ADODB.Connection
ConnectString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
& "Persist Security Info=False;Initial Catalog=陈念;" _
& "Data Source=3302A68391D44A0"
conn.CursorLocation = adUseClient
conn.Open ConnectString
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -