DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Open File Dialog and Database Location Problem

  1. #1
    Join Date
    Apr 2007

    Open File Dialog and Database Location Problem


    I have come across a problem which I'm unable to solve.

    I'm creating a VB.Net application using Visual Studio 2005. On one of my forms, I've save a new record/row to my database. On this form, it also has a Open File Dialog component, which opens a picture, so that I can save the picture to the database. The problem occurs whenever I use the Open File Dialog, and open a picture, it comes up with the error saying it can't find my database. It shows me the path is it looking for it, and its the wrong path.

    But when I don't use the Open File Dialog, it works perfectly fine. It saves the new record/row to the database. Its whenever I open a file using the Open File Dialog that it doesn't work.

    If I hit the cancel button on the Open File Dialog it will still work, its whenever I open a file that it comes up with the error of not finding my database, as it is looking in the wrong directory.

    I tried this in a new project and the same thing happens. It seems that whenever I open a file using the Open File Dialog, it is changing the path of where my database is, to the path of where the file I've just opened.

    I have no idea why this is happening, please help me.

    Here is my code for my database connection:

    'Connection to the Access database
    Public Const strConnection As String = _
    Provider=Microsoft.Jet.OLEDB.4.0; " & _
    "Data Source=./myDatabase.mdb;Persist Security Info=False"

    and here is my code for my Open File Dialog:

    OpenFileDialog.Filter = "Image files (.jpg, .jpeg, .bmp, .gif)|*.jpg;*.jpeg;*.bmp;*.gif"
    If (OpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    imageFileName = OpenFileDialog.FileName
    txtImage.Text = imageFileName
    End If

    Thanks very much, any help much appreciated.

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    You might try setting the OpenFileDialog's .RestoreDirectory property to True. A better solution, in my opinion, is to specify the full path to your database in your connection string. That is, instead of "Data Source = .\myDatabase.mdb", use "Data Source = d:\path\myDatabase.mdb".
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2007

    Thanks very much for your help and quick reponse.

    Yeh, I have now solved the problem. It seems that the OpenFileDialog was overridding my current path. So I have changed my path to the database as:

    "Data Source=|DataDirectory|/myDatabase.mdb"

    But I'm sure you way would work as well.

    Again thanks very much,


Similar Threads

  1. Replies: 1
    Last Post: 03-06-2006, 05:15 AM
  2. Save Image to Field
    By Chicho in forum VB Classic
    Replies: 11
    Last Post: 10-01-2003, 12:00 AM
  3. Replies: 5
    Last Post: 12-20-2002, 11:54 AM
  4. Adding Data to a Database Field in VB6
    By Brian Higgins in forum VB Classic
    Replies: 1
    Last Post: 11-27-2001, 12:19 AM
  5. Password on Access Database?
    By Jorge Biquez in forum VB Classic
    Replies: 3
    Last Post: 04-27-2001, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center