CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Location
    Kathmandu
    Posts
    27

    Redfine the database location

    Nice to meet u all
    i'm facing the problem of data table. I want to redfine the database location. It means i want to select database each time from application directory.

    How can we re-define the location of database in it while loading specific form.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Hi ! Every body

    I'm not 100% sure what you're asking. Maybe this will point you in the right direction:

    Use an OpenFileDialog object called in Form_Load()... something like...

    Code:
    string dbPath;
    
    public void Form_Load()
    {
        //Prompt the user to select the database to open in this form
        OpenFileDialog ofd = new OpenFileDialog();
        DialogResult dr = ofd.ShowDialog();
    
        if( dr != DialogResult.OK )
            //Kill the form
            this.Unload();  //I think
    
        //Otherwise read the path to the database
        dbPath = ofd.FileName;
    
        //Do some validation here
    }
    If, instead, you're asking how to pass in an argument to a newly created form: I have forgotten the design pattern to do that (I don't do a lot of forms programming), but I'm sure someone else here can tell you. It's simple, at any rate. You can probably google for it.

    If, instead, you want to open it based on the application directory path, see my reply to your other recent post.

    Hope that helps?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jun 2010
    Location
    Kathmandu
    Posts
    27

    Re: Hi ! Every body

    i want to get the directory location of current program. How can i get it.

  4. #4
    Join Date
    Mar 2011
    Location
    London
    Posts
    54

    Re: Hi ! Every body


  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Hi ! Every body

    A good way, IMHO, is to store the Database location in your App.Config file, like this :

    http://www.ezzylearning.com/tutorial.aspx?tid=8067328

    This ensures that when the app starts up, it already knows where the DB is.

  6. #6
    Join Date
    Jun 2010
    Location
    Kathmandu
    Posts
    27

    Re: Redfine the database location

    thank you dear friend
    It's good way...

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