VB6 : Create DSN Programatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neo008
    New Member
    • Jun 2007
    • 85

    VB6 : Create DSN Programatically

    Hi all,

    Can somebody help me about creation of Data Source Name (DSN) programatically .

    I'm using ADO control for connections. MS-Access as database

    Thanks

    -NEO
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try to use this

    1. add the required ODBC library reference from Project ---> References
    2. add 2 listboxes,1 textbox and 1 command button on the form.

    [code=vb]
    Private Sub Command1_Click( )
    Dim ds As New ODBCTool.Dsn
    If ls.ListIndex <> -1 Then
    If Len(Trim(Text1. Text)) = 0 Then
    MsgBox "Enter the name of dns"
    End If
    tt = ds.CreateDSN(Te xt1.Text, ls.List(ls.List Index), "orcl", "", "debasis", "debasis", "", False, "")
    Else
    MsgBox "Choose the Driver ..."
    End If
    End Sub

    Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
    If KeyCode = 116 Then
    Dim ds As New ODBCTool.Dsn
    Dim List1() As String
    tt = ds.GetOdbcDrive rList(List1)
    ls1.Clear
    tt = ds.GetDataSourc eList(List1)
    For I = 0 To UBound(List1) - 1
    ls1.AddItem List1(I)
    Next
    ls1.Refresh
    End If
    End Sub


    Private Sub Form_Load()
    Dim ds As New ODBCTool.Dsn
    Dim List1() As String
    tt = ds.GetOdbcDrive rList(List1)

    For I = 0 To UBound(List1) - 1
    ls.AddItem List1(I)
    Next

    tt = ds.GetDataSourc eList(List1)
    For I = 0 To UBound(List1) - 1
    ls1.AddItem List1(I)
    Next

    Command1.Enable d = ls.ListIndex <> -1 And Len(Trim(Text1. Text)) > 0
    End Sub

    Private Sub Text1_Change()
    Command1.Enable d = ls.ListIndex <> -1 And Len(Trim(Text1. Text)) > 0
    End Sub

    [/code]

    Comment

    Working...