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

📄 直接配置odbc.frm

📁 Windows API函数,希望大伙有用哦
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form 直接配置ODBC 
   BackColor       =   &H8000000A&
   Caption         =   "直接配置ODBC"
   ClientHeight    =   1995
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6165
   LinkTopic       =   "Form1"
   ScaleHeight     =   1995
   ScaleWidth      =   6165
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "修  改"
      Height          =   315
      Left            =   3309
      TabIndex        =   20
      Top             =   1200
      Width           =   840
   End
   Begin VB.CommandButton Command4 
      Caption         =   "删  除"
      Height          =   315
      Left            =   5100
      TabIndex        =   19
      Top             =   1200
      Width           =   840
   End
   Begin VB.CommandButton Command5 
      Caption         =   "首记录"
      Height          =   315
      Left            =   30
      TabIndex        =   18
      Top             =   1650
      Width           =   1170
   End
   Begin VB.CommandButton Command3 
      Caption         =   "录  入"
      Height          =   315
      Left            =   4204
      TabIndex        =   17
      Top             =   1200
      Width           =   840
   End
   Begin VB.TextBox Text6 
      Alignment       =   1  'Right Justify
      BackColor       =   &H80000001&
      Enabled         =   0   'False
      Height          =   285
      Left            =   1410
      TabIndex        =   15
      Text            =   "Text6"
      Top             =   1200
      Width           =   855
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   4800
      Top             =   150
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command9 
      Caption         =   "退  出"
      Height          =   315
      Left            =   4800
      TabIndex        =   14
      Top             =   1650
      Width           =   1170
   End
   Begin VB.CommandButton Command8 
      Caption         =   "末记录"
      Height          =   315
      Left            =   3606
      TabIndex        =   13
      Top             =   1650
      Width           =   1170
   End
   Begin VB.CommandButton Command7 
      Caption         =   "下一记录 >"
      Height          =   315
      Left            =   2414
      TabIndex        =   12
      Top             =   1650
      Width           =   1170
   End
   Begin VB.CommandButton Command6 
      Caption         =   "< 前一记录"
      Height          =   315
      Left            =   1222
      TabIndex        =   11
      Top             =   1650
      Width           =   1170
   End
   Begin VB.CommandButton Command1 
      BackColor       =   &H80000009&
      Caption         =   "查  询"
      Height          =   315
      Left            =   2400
      TabIndex        =   10
      Top             =   1200
      Width           =   840
   End
   Begin VB.TextBox Text5 
      Alignment       =   1  'Right Justify
      DataField       =   "基本工资"
      DataSource      =   "Adodc1"
      Height          =   270
      Left            =   4995
      TabIndex        =   9
      Text            =   "Text5"
      Top             =   810
      Width           =   855
   End
   Begin VB.TextBox Text4 
      Alignment       =   1  'Right Justify
      DataField       =   "最后学历"
      DataSource      =   "Adodc1"
      Height          =   270
      Left            =   2700
      TabIndex        =   7
      Text            =   "Text4"
      Top             =   810
      Width           =   1080
   End
   Begin VB.TextBox Text3 
      Alignment       =   2  'Center
      DataField       =   "性别"
      DataSource      =   "Adodc1"
      Height          =   270
      Left            =   960
      TabIndex        =   6
      Text            =   "Text3"
      Top             =   810
      Width           =   375
   End
   Begin VB.TextBox Text2 
      Alignment       =   1  'Right Justify
      DataField       =   "出生日期"
      DataSource      =   "Adodc1"
      Height          =   270
      Left            =   2880
      TabIndex        =   3
      Text            =   "Text2"
      Top             =   195
      Width           =   1830
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      DataField       =   "姓名"
      DataSource      =   "Adodc1"
      Height          =   285
      Left            =   930
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   210
      Width           =   810
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "请输入姓名:"
      Height          =   180
      Left            =   240
      TabIndex        =   16
      Top             =   1260
      Width           =   1080
   End
   Begin VB.Label Label8 
      Caption         =   "性别:"
      Height          =   240
      Left            =   240
      TabIndex        =   8
      Top             =   840
      Width           =   570
   End
   Begin VB.Label Label7 
      AutoSize        =   -1  'True
      Caption         =   "基本工资:"
      Height          =   180
      Left            =   4005
      TabIndex        =   5
      Top             =   840
      Width           =   900
   End
   Begin VB.Label Label6 
      Caption         =   "最后学历:"
      Height          =   285
      Left            =   1785
      TabIndex        =   4
      Top             =   840
      Width           =   960
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "出生日期:"
      Height          =   180
      Left            =   1980
      TabIndex        =   2
      Top             =   240
      Width           =   900
   End
   Begin VB.Label Label1 
      Caption         =   "姓名:"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   240
      Width           =   600
   End
End
Attribute VB_Name = "直接配置ODBC"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As Any, ByVal cbData As Long) As Long
Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Dim Falg As Integer
Private Sub Form_Load()
Dim hKey As Long
Text1 = "": Text2 = "": Text3 = "": Text4 = "": Text5 = "": Text6 = ""
TxtLock
   RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKey
   RegSetValueEx hKey, "职工情况", 0&, REG_SZ, "SQL Server", Len("SQL Server")
   RegCloseKey hKey
   RegCreateKey HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\职工情况", hKey
   RegSetValueEx hKey, "Database", 0&, REG_SZ, "职工情况", 2 * Len("职工情况")
   RegSetValueEx hKey, "Driver", 0&, REG_SZ, "C:\WINDOWS\SYSTEM\SQLSRV32.DLL", Len("C:\WINDOWS\System\SQLSRV32.DLL")
   RegSetValueEx hKey, "LastUser", 0&, REG_SZ, "Yao Wei 166", Len("Yao Wei 166")
   RegSetValueEx hKey, "Server", 0&, REG_SZ, "YAO_WEI_SERVER", Len("YAO_WEI_SERVER")
   RegSetValueEx hKey, "Trusted_Connection", 0&, REG_SZ, "Yes", Len("Yes")
   RegCloseKey hKey
   Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;" & _
     "Extended Properties=DSN=职工情况;APP=Visual Basic;WSID=YAO_WEI_SERVER;" & _
     "DATABASE=职工情况;Trusted_Connection=Yes"
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "表1"
Adodc1.Refresh
End Sub
Private Sub Command1_Click()
Text6.BackColor = &H80000005
Text6.Enabled = True
Text6.SetFocus
 Falg = 1: CmdUnEnabled
End Sub
Private Sub Command2_Click()
Text6.BackColor = &H80000001
Falg = 0: CmdEnabled
TxtUnLock
End Sub
Private Sub Command3_Click()
On Error Resume Next
Text6.BackColor = &H80000001
Falg = 0: CmdEnabled
TxtUnLock
Adodc1.Recordset.AddNew
Text1.SetFocus
End Sub
Private Sub Command4_Click()
On Error Resume Next
Text6.BackColor = &H80000001
Falg = 0: CmdEnabled
Adodc1.Recordset.Delete
Adodc1.Refresh
End Sub
Private Sub Command5_Click()
 Adodc1.Recordset.MoveFirst
End Sub
Private Sub Command6_Click()
If Falg = 1 Then
  Adodc1.Recordset.MovePrevious
  Adodc1.RecordSource = "Select * from 表1 Where [姓名] Like" + "'" + Text6 + "%" + "'"
   If Text1 = "" Then
     MsgBox "  记录查询完毕   !  ", vbExclamation
     Exit Sub
   End If
   Else
  Adodc1.Recordset.MovePrevious
    If Adodc1.Recordset.AbsolutePosition = adPosBOF Then
       Adodc1.Recordset.MoveFirst
       MsgBox "    已经是第一条记录  !    ", vbExclamation, "提示信息"
    End If
  End If
End Sub
Private Sub Command7_Click()
If Falg = 1 Then
  Adodc1.Recordset.MoveNext
  Adodc1.RecordSource = "Select * from 表1 Where [姓名] Like" + "'" + Text6 + "%" + "'"
   If Text1 = "" Then
     MsgBox "  记录查询完毕   !  ", vbExclamation
     Exit Sub
   End If
   Else
   Adodc1.Recordset.MoveNext
  If Adodc1.Recordset.AbsolutePosition = adPosEOF Then
   Adodc1.Recordset.MoveLast
  MsgBox "    已经是最后一条记录  !    ", vbExclamation, "提示信息"
End If
End If
End Sub
Private Sub Command8_Click()
 Adodc1.Recordset.MoveLast
End Sub
Private Sub Command9_Click()
On Error Resume Next
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Unload Me
End
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
 Adodc1.RecordSource = "Select * from 表1 Where [姓名] Like" + "'" + Text6 + "%" + "'"
 Adodc1.Refresh
End If
End Sub
Private Sub CmdUnEnabled()
Command5.Enabled = False: Command8.Enabled = False
End Sub
Private Sub CmdEnabled()
Command5.Enabled = True: Command8.Enabled = True
End Sub
Private Sub TxtLock()
Text1.Locked = True: Text2.Locked = True: Text3.Locked = True: Text4.Locked = True: Text5.Locked = True
End Sub
Private Sub TxtUnLock()
Text1.Locked = False: Text2.Locked = False: Text3.Locked = False: Text4.Locked = False: Text5.Locked = False
End Sub

⌨️ 快捷键说明

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