📄 dlgconnecttodatabase.frm
字号:
VERSION 5.00
Begin VB.Form dlgConnectToDatabase
BorderStyle = 3 'Fixed Dialog
Caption = "连接数据库"
ClientHeight = 2385
ClientLeft = 2760
ClientTop = 3750
ClientWidth = 4800
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2385
ScaleWidth = 4800
ShowInTaskbar = 0 'False
Begin VB.CommandButton btnBrowserServer
Caption = "..."
Height = 315
Left = 3660
TabIndex = 10
Top = 240
Width = 435
End
Begin VB.ComboBox combServer
Height = 300
Left = 1560
TabIndex = 9
Top = 240
Width = 2055
End
Begin VB.TextBox txtPassword
Height = 315
IMEMode = 3 'DISABLE
Left = 1560
PasswordChar = "*"
TabIndex = 8
Text = "admin"
Top = 1320
Width = 2415
End
Begin VB.TextBox txtUserName
Height = 315
Left = 1560
TabIndex = 7
Text = "Admin"
Top = 960
Width = 2415
End
Begin VB.TextBox txtDatabaseName
Height = 315
Left = 1560
TabIndex = 6
Text = "Insurance"
Top = 600
Width = 2415
End
Begin VB.CommandButton CancelButton
Caption = "取消"
Height = 375
Left = 2220
TabIndex = 1
Top = 1860
Width = 1215
End
Begin VB.CommandButton OKButton
Caption = "连接"
Height = 375
Left = 900
TabIndex = 0
Top = 1860
Width = 1215
End
Begin VB.Label Label4
Caption = "密码:"
Height = 255
Left = 300
TabIndex = 5
Top = 1320
Width = 1335
End
Begin VB.Label Label3
Caption = "用户名:"
Height = 315
Left = 300
TabIndex = 4
Top = 960
Width = 1215
End
Begin VB.Label Label2
Caption = "数据库名称:"
Height = 315
Left = 300
TabIndex = 3
Top = 600
Width = 1095
End
Begin VB.Label Label1
Caption = "服务器地址:"
Height = 315
Left = 300
TabIndex = 2
Top = 240
Width = 1635
End
End
Attribute VB_Name = "dlgConnectToDatabase"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public LoginSucceeded As Boolean
'引用Microsoft ActiveX Data Objects 2.6 Library
'定义连接对象和记录集
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
Private Sub btnBrowserServer_Click()
Me.Enabled = False
combServer.Clear
'枚举网络中所有的SQL Server,将其添加到服务器列表中
Dim oSQLServerDMOApp As SQLDMO.Application
Set oSQLServerDMOApp = New SQLDMO.Application
Dim i As Integer
Dim namX As NameList
Set namX = oSQLServerDMOApp.ListAvailableSQLServers
For i = 1 To namX.Count
combServer.AddItem namX.Item(i)
Next
'Show top server
combServer.ListIndex = 0
Me.Enabled = True
End Sub
Private Sub CancelButton_Click()
LoginSucceeded = False
Me.Hide
End Sub
Private Sub Form_Load()
combServer.Clear
combServer.AddItem "(local)"
combServer.ListIndex = 0
LoginSucceeded = False
End Sub
Private Sub OKButton_Click()
Set conn = New ADODB.Connection
CommModule.connString = "driver={sql server};server=" + Me.combServer.text + ";uid=" + Me.txtUserName.text + ";pwd=" + Me.txtPassword.text + ";Database=" + Me.txtDatabaseName.text + ";"
conn.ConnectionString = connString
conn.ConnectionTimeout = 50
conn.Open
LoginSucceeded = True
Me.Hide
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -