⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmconnect.frm

📁 大量优秀的vb编程
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmConnect 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "RDO连接数据库"
   ClientHeight    =   4944
   ClientLeft      =   48
   ClientTop       =   336
   ClientWidth     =   7092
   Icon            =   "frmConnect.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4944
   ScaleWidth      =   7092
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "退出程序"
      Height          =   495
      Left            =   5160
      TabIndex        =   26
      Top             =   4320
      Width           =   1575
   End
   Begin VB.CommandButton cmdSQL 
      Caption         =   "执行SQL语句"
      Height          =   495
      Left            =   1800
      TabIndex        =   13
      Top             =   4320
      Width           =   1575
   End
   Begin VB.Frame Frame1 
      Caption         =   "连接信息"
      Height          =   1815
      Left            =   4440
      TabIndex        =   23
      Top             =   240
      Width           =   2415
      Begin VB.Label Label12 
         AutoSize        =   -1  'True
         Caption         =   "Label12"
         Height          =   195
         Left            =   240
         TabIndex        =   25
         Top             =   1200
         Width           =   570
      End
      Begin VB.Label Label11 
         AutoSize        =   -1  'True
         Caption         =   "Label11"
         Height          =   195
         Left            =   240
         TabIndex        =   24
         Top             =   600
         Width           =   570
      End
   End
   Begin VB.TextBox txtWSID 
      Height          =   285
      Left            =   1440
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   1680
      Width           =   2775
   End
   Begin VB.CommandButton cmdDisconnect 
      Caption         =   "关闭连接"
      Height          =   495
      Left            =   3480
      TabIndex        =   12
      Top             =   4320
      Width           =   1575
   End
   Begin VB.ComboBox cboPrompt 
      Height          =   276
      Left            =   1200
      Style           =   2  'Dropdown List
      TabIndex        =   10
      Top             =   3960
      Width           =   2775
   End
   Begin VB.TextBox txtDSName 
      Height          =   285
      Left            =   3360
      TabIndex        =   9
      Text            =   "Text9"
      Top             =   5400
      Visible         =   0   'False
      Width           =   2775
   End
   Begin VB.TextBox txtConnect 
      Height          =   645
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   8
      Text            =   "frmConnect.frx":000C
      Top             =   3200
      Width           =   6735
   End
   Begin VB.TextBox txtAPP 
      Height          =   285
      Left            =   1440
      TabIndex        =   7
      Text            =   "Text7"
      Top             =   2760
      Width           =   2775
   End
   Begin VB.TextBox txtDSN 
      Height          =   285
      Left            =   1440
      TabIndex        =   6
      Text            =   "Text6"
      Top             =   2400
      Width           =   2775
   End
   Begin VB.TextBox txtDriver 
      Height          =   285
      Left            =   1440
      TabIndex        =   5
      Text            =   "Text5"
      Top             =   2040
      Width           =   2775
   End
   Begin VB.TextBox txtServer 
      Height          =   285
      Left            =   1440
      TabIndex        =   3
      Text            =   "Text4"
      Top             =   1320
      Width           =   2775
   End
   Begin VB.TextBox txtDatabase 
      Height          =   285
      Left            =   1440
      TabIndex        =   2
      Text            =   "Text3"
      Top             =   960
      Width           =   2775
   End
   Begin VB.TextBox txtPWD 
      Height          =   285
      Left            =   1440
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   600
      Width           =   2775
   End
   Begin VB.TextBox txtUID 
      Height          =   285
      Left            =   1440
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   240
      Width           =   2775
   End
   Begin VB.CommandButton Connect 
      Caption         =   "连接数据库"
      Height          =   495
      Left            =   120
      TabIndex        =   11
      Top             =   4320
      Width           =   1575
   End
   Begin VB.Label Label10 
      AutoSize        =   -1  'True
      Caption         =   "工作站名称"
      Height          =   180
      Left            =   120
      TabIndex        =   22
      Top             =   1728
      Width           =   900
   End
   Begin VB.Label Label9 
      AutoSize        =   -1  'True
      Caption         =   "显示方式"
      Height          =   180
      Left            =   120
      TabIndex        =   21
      Top             =   4008
      Width           =   720
   End
   Begin VB.Label Label7 
      AutoSize        =   -1  'True
      Caption         =   "应用程序"
      Height          =   180
      Left            =   120
      TabIndex        =   20
      Top             =   2808
      Width           =   720
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      Caption         =   "数据源名称"
      Height          =   180
      Left            =   120
      TabIndex        =   19
      Top             =   2448
      Width           =   900
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "数据库类型"
      Height          =   180
      Left            =   120
      TabIndex        =   18
      Top             =   2088
      Width           =   900
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "服务器名称"
      Height          =   180
      Left            =   120
      TabIndex        =   17
      Top             =   1368
      Width           =   900
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "数据库"
      Height          =   180
      Left            =   120
      TabIndex        =   16
      Top             =   1008
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "密码"
      Height          =   180
      Left            =   120
      TabIndex        =   15
      Top             =   648
      Width           =   360
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "用户名"
      Height          =   180
      Left            =   120
      TabIndex        =   14
      Top             =   288
      Width           =   540
   End
End
Attribute VB_Name = "frmConnect"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public gDBase As rdoConnection

Private Sub cmdDisconnect_Click()
On Error GoTo HandleError
    
    gDBase.Close
    MsgBox "Disconnected OK"
    cmdDisconnect.Enabled = False
    Label11.Caption = "No Connection"
    Label12.Caption = ""
    cmdSQL.Visible = False
    Exit Sub
    
HandleError:
    HandleErr "frmConnect.cmdDisconnect_Click"
End Sub

Private Sub cmdSQL_Click()
    frmSQL.Show vbModal, Me
End Sub

Private Sub Command1_Click()
    End
End Sub

Private Sub Connect_Click()
On Error GoTo HandleError
Dim gEnviron As rdoEnvironment
    
    Set gEnviron = rdoEngine.rdoEnvironments(0)
    rdoEnvironments(0).CursorDriver = rdUseOdbc
    gEnviron.LoginTimeout = 15
    DoEvents
    
    Set gDBase = gEnviron.OpenConnection(dsname:=txtDSName, prompt:=cboPrompt.ListIndex, Connect:=txtConnect.Text)
    MsgBox "Connected OK"
    cmdDisconnect.Enabled = True
    If gDBase.Updatable Then
        Label11.Caption = "Database is updatable"
    Else
        Label11.Caption = "Database is not updatable"
    End If
    Label12.Caption = "Number of tables : " & CStr(gDBase.rdoTables.Count)
    cmdSQL.Visible = True
    
    Exit Sub
    
HandleError:
    HandleErr "frmConnect.Connect_Click"
End Sub

Private Sub Form_Load()
    txtUID = "sa"
    txtPWD = ""
    txtDatabase = "pubs"
    txtServer = "LT"
    txtWSID = "LT"
    txtDriver = "SQL Server"
    txtDSN = "pubs"
    txtAPP = App.EXEName
    txtDSName = ""
    cboPrompt.Clear
    cboPrompt.AddItem "rdDriverPrompt", 0
    cboPrompt.AddItem "rdDriverNoPrompt", 1
    cboPrompt.AddItem "rdDriverComplete", 2
    cboPrompt.AddItem "rdDriverCompleteRequired", 3
    cboPrompt.ListIndex = 1
    cmdDisconnect.Enabled = False
    Label11.Caption = "No Connection"
    Label12.Caption = ""
    cmdSQL.Visible = False
End Sub

Private Function BuildConnect() As String
On Error GoTo HandleError
    Dim sConnect As String
    
    sConnect = "UID=" & txtUID & ";" & _
               "PWD=" & txtPWD & ";" & _
               "DATABASE=" & txtDatabase & ";" & _
               "SERVER=" & txtServer & ";" & _
               "WSID=" & txtWSID & ";" & _
               "DRIVER=" & txtDriver & ";" & _
               "DSN=" & txtDSN & ";" & _
               "APP=" & txtAPP
    BuildConnect = sConnect
    
    Exit Function
HandleError:
    HandleErr "frmConnect.BuildConnect"
End Function

Private Sub Form_Unload(Cancel As Integer)
    If cmdDisconnect.Enabled Then
        cmdDisconnect_Click
    End If
    Unload frmSQL
    Unload Me
End Sub

Private Sub txtAPP_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtDatabase_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtDriver_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtDSN_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtPWD_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtServer_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtUID_Change()
    txtConnect = BuildConnect
End Sub

Private Sub txtWSID_Change()
    txtConnect = BuildConnect
End Sub

⌨️ 快捷键说明

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