CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help needed

  1. #1
    Join Date
    Mar 2001
    Posts
    4

    Help needed

    Hi guys!

    Can, please anyone tell me, how do set Database to Dataenvironment in code rather then by properties?

    The problem is, that I have a Datareport with Data environment and the connection to the Database is made in its properties. When I'll deploy my App I don't know if it will be in the same folder as it is on my PC.

    I was thinking something about like: Dataenvironment1.databasename=App.Path & "\MyDataBase"

    If it's possible, please DO help me.

    God bless you all! Ales


  2. #2
    Join Date
    Dec 1999
    Location
    Germany
    Posts
    26

    Re: Help needed

    Hi!

    If I understand you correctly, you want to be able to dynamically access this database. You can do so exactly as you proposed. In case you are using a data-control:
    Formname.Controlname.Databasename = Filename


    In case you are using a Databaseobject:
    set DB = OpenDatabase(Filename)


    Only be careful with one thing. I have noticed, I think, this may not be reliable :-), that App.Path does not always end on \ but sometimes does (Depending on installation in Subdir or directly on a drive). So what I always do is create a variable named AppPath and do the following:
    Dim AppPath as string
    AppPath = App.Path
    If Right(AppPath, 1) <> "\" then AppPath = AppPath & "\"



    So you will only have to specify your filename as:
    Filename = AppPath & "MyDatabasefile.mdb"


    or whatever your database is named like...

    Hope this helps you


  3. #3
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: Help needed

    Try this, it works for me... In DataEnvironment1 enter:


    private Sub DataEnvironment_Initialize()
    Connection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & App.Path & "\database_name.mdb;" & _
    "Mode=ReadWrite|Share Deny None;" & _
    "Persist Security Info=false"
    End Sub





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