📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "使用非DSN的ODBC连接SQL Server数据库"
ClientHeight = 6240
ClientLeft = 60
ClientTop = 345
ClientWidth = 8055
LinkTopic = "Form1"
ScaleHeight = 6240
ScaleWidth = 8055
StartUpPosition = 1 '所有者中心
Begin VB.Frame Frame2
Caption = "药品信息浏览"
Height = 5505
Left = 2205
TabIndex = 4
Top = 630
Width = 5805
Begin VB.TextBox Text1
Height = 330
Index = 9
Left = 1065
TabIndex = 15
Top = 5085
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 8
Left = 1065
TabIndex = 14
Top = 4575
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 7
Left = 1065
TabIndex = 13
Top = 4050
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 6
Left = 1065
TabIndex = 12
Top = 3510
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 5
Left = 1065
TabIndex = 11
Top = 2985
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 4
Left = 1065
TabIndex = 10
Top = 2460
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 3
Left = 1065
TabIndex = 9
Top = 1905
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 2
Left = 1065
TabIndex = 8
Top = 1365
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 1
Left = 1065
TabIndex = 7
Top = 825
Width = 4635
End
Begin VB.TextBox Text1
Height = 330
Index = 0
Left = 1065
TabIndex = 6
Top = 315
Width = 4635
End
Begin VB.Label Label3
Caption = $"Form1.frx":0000
Height = 5115
Left = 135
TabIndex = 5
Top = 345
Width = 945
End
End
Begin MSComctlLib.ImageList ImageList1
Left = -60
Top = 2715
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 2
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":012D
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":0A09
Key = ""
EndProperty
EndProperty
End
Begin VB.Frame Frame1
Height = 5505
Left = 90
TabIndex = 1
Top = 630
Width = 2145
Begin VB.CommandButton Command1
Caption = "退出"
Height = 375
Left = 75
TabIndex = 16
Top = 5010
Width = 1995
End
Begin VB.ListBox List1
Height = 4380
Left = 120
TabIndex = 3
Top = 495
Width = 1890
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "请点击药品名称:"
ForeColor = &H000000FF&
Height = 315
Left = 165
TabIndex = 2
Top = 225
Width = 1485
End
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "药品信息浏览"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 465
Left = 3165
TabIndex = 0
Top = 120
Width = 1995
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i As Integer '定义一个整型变量
Dim cn As New ADODB.Connection '定义数据连接
Dim rs As New ADODB.Recordset '定义数据集对象
Private Sub Form_Load()
'打开连接
'SERVER为指定的服务器;UID为登录身份;PWD为密码;DATABASE为数据库
cn.ConnectionString = "DRIVER=SQL Server;SERVER=" & "" & ";UID=sa;PWD=" & "" & ";DATABASE=YYGLXT"
cn.Open
rs.Open "select * from kc", cn, adOpenKeyset, adLockOptimistic
'向List列表中添加“商品名称”信息
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While rs.EOF = False
List1.AddItem (rs.Fields("商品名称"))
rs.MoveNext
Loop
End If
rs.Close
End Sub
Private Sub List1_Click()
rs.Open "select * from kc where 商品名称='" + List1.Text + "'", cn, adOpenKeyset, adLockOptimistic
For i = 0 To 9
If rs.RecordCount > 0 Then
'给text1数组控件赋值
Text1(i).Text = rs.Fields(i)
End If
Next i
rs.Close
End Sub
Private Sub Command1_Click()
cn.Close
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -