CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 1999
    Posts
    7

    ADO Data Controls/Connect String

    I'm pretty new to VB programming, so I hope this isn't a totally stupid question!

    Anyways, I am writing an application to a SQL Server database and have created a login screen to get the username and password for the database. I use the username and password to create a connection string and placed it in the variable strConnectString. The question is: how do I use this variable strConnectString in an ADO Data Control? I have tried placing it in the properties for the ADO Data Control but it doesn't work. I figure I'll have to put in some area of code, but where? I don't want to have to hard code the username and password in the ADO Data Control properties.

    Any help most gratefully appreciated!

    Bud


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: ADO Data Controls/Connect String

    here is a sample

    Dim youruid as string
    Dim yourpwd as string
    youruid = ' get this from a dialog
    yourpwd = ' get this from a dialog
    Adodc1.ConnectionString = "DSN=yourDSNgoesHere;uid=" & youruid & ";PWD=" & yourpwd & ";database=yourDatabase"
    Adodc1.RecordSource = "select name from sysobjects" ' your recordsource
    Adodc1.Refresh



    place this code e.g. in a command buttonclick event.
    I did NOT set any properties for the data control at runtime.
    tested in nt4, vb6, sql 6.5


  3. #3
    Join Date
    Oct 1999
    Posts
    7

    Re: ADO Data Controls/Connect String

    Lothar,

    That was exactly what I needed! I placed the code in the Form_Load() subroutine of the form I had the ADO Data Control in and it worked perfectly.

    Many thanks,
    Bud


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured