If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Open File Dialog and Database Location Problem

Hi,

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.

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".