• 注册
  • 关于作者
    企业认证:趣记站长
    关注 6 粉丝 4 喜欢 9 内容 992
    江西省·南昌市
    聊天 送礼
    • 查看作者
    • 通用数据链接文件 (*.UDL) 的竖立

      援引 Microsoft OLE DB Service Component 1.0 Type Library

      Option Explicit

      Private Sub Command1_Click()

      Dim x As New MSDASC.DataLinks

      x.hWnd = Me.hWnd

      Dim s As String

      On Error GoTo ErrorHandler

      s = x.PromptNew

      On Error GoTo 0

      If VBA.Len(VBA.Trim(s & "")) > 0 Then

      Dim CommonDialog1 As New MSComDlg.CommonDialog

      CommonDialog1.DefaultExt = ".udl"

      CommonDialog1.Filter = "通用数据链接文件 (*.UDL)|*.udl"

      CommonDialog1.DialogTitle = "保存为通用数据链接文件"

      CommonDialog1.Flags = cdlOFNOverwritePrompt

      CommonDialog1.CancelError = True

      On Error GoTo ErrorHandler

      CommonDialog1.ShowSave

      On Error GoTo 0

      s = "[oledb]" & vbCrLf _

      & "; Everything after this line is an OLE DB initstring" & vbCrLf _

      & s & vbCrLf

      Dim BytesBuffer() As Byte

      BytesBuffer = VBA.StrConv(VBA.StrConv(s, vbUnicode), vbFromUnicode)

      Dim i As Long

      ReDim BytesBuffer0(1) As Byte

      BytesBuffer0(0) = 255 诠释:&HFF

      BytesBuffer0(1) = 254 诠释:&HFE

      If VBA.Len(VBA.Trim(VBA.Dir(CommonDialog1.FileName))) > 0 Then

      VBA.Kill CommonDialog1.FileName

      End If

      On Error GoTo ErrorHandler

      i = VBA.FreeFile

      Open CommonDialog1.FileName For Binary Access Write As #i

      Put #i, , BytesBuffer0

      Put #i, , BytesBuffer

      Close #i

      On Error GoTo 0

      If VBA.MsgBox("Test?", vbYesNo) = vbYes Then

      Dim adoConnection As New ADODB.Connection

      adoConnection.Open "File Name=" & CommonDialog1.FileName

      VBA.MsgBox "OK!"

      End If

      End If

      Exit Sub

      ErrorHandler:

      If Err.Number <> 91 And Err.Number <> 32755 Then

      VBA.MsgBox Err.Number & ":" & vbCrLf & Err.Description

      End If

      End Sub

      Private Sub Command2_Click()

      Dim CommonDialog1 As New MSComDlg.CommonDialog

      CommonDialog1.DefaultExt = ".udl"

      CommonDialog1.Filter = "通用数据链接文件 (*.UDL)|*.udl"

      CommonDialog1.DialogTitle = "掀开通用数据链接文件"

      诠释:CommonDialog1.Flags = cdlOFNOverwritePrompt

      CommonDialog1.CancelError = True

      On Error GoTo ErrorHandler

      CommonDialog1.ShowOpen

      On Error GoTo 0

      If VBA.Len(VBA.Trim(VBA.Dir(CommonDialog1.FileName))) > 0 Then

      VBA.MsgBox GetConnectionStringFromUDL(CommonDialog1.FileName)

      End If

      Exit Sub

      ErrorHandler:

      If Err.Number <> 91 And Err.Number <> 32755 Then

      VBA.MsgBox Err.Number & ":" & vbCrLf & Err.Description

      End If

      End Sub

      Public Function GetConnectionStringFromUDL(UDLFileName As String) As String

      If VBA.Len(VBA.Trim(VBA.Dir(UDLFileName & ""))) > 0 Then

      Dim BytesBuffer() As Byte

      ReDim BytesBuffer(VBA.FileLen(UDLFileName) - 133) As Byte

      Dim i As Long

      i = VBA.FreeFile

      Open UDLFileName For Binary Access Read As #i

      Get #i, 129, BytesBuffer

      Close #i

      GetConnectionStringFromUDL = VBA.Trim(VBA.StrConv(VBA.StrConv(BytesBuffer, vbFromUnicode), vbUnicode))

      End If

      End Function

      C++程序设计从零开始之语句
      C语言编程程序的内存如何布局,C语言编写linux下的守护进程,在C++中创建持久对象,C++中类的数据成员的安全隐患,经典c程序100例(91--100),经典c程序100例(81--90),经典c程序100例(71--80),经典c程序100例(61--70),经典c程序100例(51--60),经典c程序100例(41--50),经典c程序100例(31--40),经典c程序100例(21--30),经典c程序100例(11--20),经典c程序100例(1--10),实例解析C++/CLI的串行化,用C语言编写Windows服务程序的五个步骤,自定义类_string类,关于拷贝构造函数和赋值运算符,用c语言演绎“生命游戏”,c语言中时间陷阱的实现
      C/C++

    • 0
    • 0
    • 0
    • 79
    • 单栏布局 侧栏位置: