|
|
#1 |
|
Junior Member
Join Date: Aug 06
Location: Linköping, Sweden
Posts: 20
![]() |
Hi guys!
I'm using an openfiledialog along with some other textboxes and so and then extracting the text from the textboxes and putting them into my database. When I open a file with the dialog I also take the path to the file and put it in to a textbox to save it later in the database. But this is where it all goes wrong, it works fine to save if I don't import a picture, but once I import a picture (it goes in a picture box for preview and path in the textbox) then when I add the stuff to the database it changes the path to the database, replacing it with the path to the image? :S And I just can't figure out why! I've tried everything, I tried writing the path to a textfile instead, same error, even when that code is outside the db-connection. Even if I don't put in any code relating to saving the image in the database or anywhere else I still get the same error as long as I import an image to my picturebox! I really need help! Here's the code for importing the image, and saving it to my database: vb Code:
vb Code:
|
|
|
|
|
|
#2 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 61,544
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [2005] Problem saving image path to db
It's because of this:
Code:
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=movies.mdb;")
One of the things that can change it is an OpenFileDialog. A quick fix is to set the RestoreDirectory property of the OFD to True so it doesn't change the current directory, but that's not a proper solution. There's no guarantee that something else won't change the current directory. Unless you specifically want to follow the current directory you shouldn't use a path that implies the current directory. If you want a path that refers to the folder that contains the executable then that's what you should use. In a .NET connection string that looks like this: vb Code:
__________________
![]() 2007-2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW* |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Aug 06
Location: Linköping, Sweden
Posts: 20
![]() |
Re: [2005] Problem saving image path to db
Thanks Jim!
I solved it by creating a new string that contains the Application.Startuppath plus the db name. Then changing the source to that string.
|
|
|
|
|
|
#4 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 61,544
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [RESOLVED] [2005] Problem saving image path to db
Why do that when you can do it "properly" with |DataDirectory|? That's specifically why the |DataDirectory| variable exists.
__________________
![]() 2007-2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW* |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|