wessamzeidan Posted March 13, 2004 Posted March 13, 2004 Hi, I have a form with a textbox and two buttons. I use one button to open a OpenFileDialog box to choose a file, and the other button to add the chosen file name to a database. The problem is that, If I type the path of the file in the textbox, it works fine, but if I choose it using the OpenFileDialog box, I get an error telling me that it couldn't find the database. The problem is that it looks for the database file in the same folder that I chose the file to add from. I'm using access database, heres the connectionstring that I'm using 'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""MediaDB.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False' Any one knows whats going wrong???? Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
iebidan Posted March 15, 2004 Posted March 15, 2004 What will be more helpful will be the code you use, post an example or your project Quote Fat kids are harder to kidnap
samsmithnz Posted March 15, 2004 Posted March 15, 2004 'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""MediaDB.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False' iebidan's right we're going to need to see some code... but that connectionstring... I've never seen one so long... do you actually use all those options?!?! :D :D Quote Thanks Sam http://www.samsmith.co.nz
GMMorris Posted March 15, 2004 Posted March 15, 2004 Some of those options repeat them selves - that may be what is causing you trouble. Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
Moderators Robby Posted March 15, 2004 Moderators Posted March 15, 2004 That connection string was probably setup using a wizard, if you want to set a DB file at runtime then you will need to set the entire connection string at runtime. Either way runtime is the easiest way. Quote Visit...Bassic Software
wessamzeidan Posted March 15, 2004 Author Posted March 15, 2004 Thats what I did, I set the connectionstring at runtime. But now I have another problem. My application copies files to a folder thats in the same folder as the application, I was using relative addressing ' for example, instead of using c:\myprog\media, I just use media', and it was working fine. But after I started using OpenFileDialog, I got these errors that the folder media is not found, it looks for the folder media in the same folder that I chose a file using OpenFileDialog......... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Moderators Robby Posted March 15, 2004 Moderators Posted March 15, 2004 What's your code look like in the OpenFileDialog ? Quote Visit...Bassic Software
Klogg Posted March 15, 2004 Posted March 15, 2004 (edited) This happened to me in VB. When you use an OpenFileDialog, for some reason it switches the default folder to the folder that is picked in that. I fixed the problem by writing the path of the file to open as: Application.StartupPath & "\NameOfFile" Hope this helps. Edited March 15, 2004 by Klogg Quote Take a look at my programs. Go to my web site.
wessamzeidan Posted March 16, 2004 Author Posted March 16, 2004 If (Me.OpenFileDialog1.ShowDialog = DialogResult.OK) Then _filename = Me.OpenFileDialog1.FileName Me.txtFileName.Text = _filename End If I use this on a buttons click event. As Klogg said, after I used the OpenFileDialog, the default folder changes to the folder that I navigated to... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.