moddsn.bas

来自「Inventory control system」· BAS 代码 · 共 40 行

BAS
40
字号
Attribute VB_Name = "modDSN"
Private Const ODBC_ADD_SYS_DSN = 4        ' Add data source
Private Const ODBC_CONFIG_DSN = 2         ' Configure (edit) data Source
Private Const ODBC_REMOVE_DSN = 3         ' Remove data source
Private Const vbAPINull As Long = vbNull  ' NULL Pointer


'Function Declare
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
          (ByVal hwndParent As Long, ByVal fRequest As Long, _
          ByVal lpszDriver As String, ByVal lpszAttributes As String) _
          As Long

Public Sub createDSN()
    'Creating the DSN

    #If Win32 Then
          Dim intRet As Long
    #Else
          Dim intRet As Integer
    #End If

    Dim strDriver As String
    Dim strAttributes As String

    strDriver = "Microsoft Access Driver (*.mdb)"

    strAttributes = strAttributes & "DESCRIPTION=" & "VT Marketing DSN " & Chr$(0)
    strAttributes = strAttributes & "DSN=" & "VT" & Chr$(0)
    strAttributes = strAttributes & "PWD=" & "jaypee" & Chr$(0)
    strAttributes = strAttributes & "UID=" & "admin" & Chr$(0)
    strAttributes = strAttributes & "DBQ=" & DBPath & Chr$(0)

    intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, _
    strDriver, strAttributes)

    ' DSN created
End Sub

⌨️ 快捷键说明

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