Denaes Posted April 5, 2004 Posted April 5, 2004 I have a DataConnection, 8 dataAdapters and a dataset all on my main form. By dragging my database from the Server Explorer, I saved like 20 pages of code setting up the dataAdapters. But now that most of my main work is done, I need to test on another machine. And the DataConnection is a fixed path to the Access database. I know how to change a path to make it dynamic, so that wherever you move your program, the database is found: Path = Application.StartupPath & "\Data.mdb" But in the visual controls, you're only allowed to select a predefined database path: Ex: C:\Database\Test\Data.mdb You can change a fixed path, but not make it dynamic. I even went into the generated code for the control on the form and changed it there, but got an error that Application.StartupPath wasn't proper formatting. I tried to change the connectionstring on formload, right before I actually connect to the database, but the dataAdaptors must have already grabbed the old connection string because they keep using that. Is there a solution to this that would let me keep my dataAdaptors (I don't care about making other objects via code, but data adaptors with databases of 10+columns are a ***** to write properties for by hand) but let me change the database location to something more dynamic? Quote
Arch4ngel Posted April 5, 2004 Posted April 5, 2004 First Close the connection. Change the connection string. (You can put your DB on a Shared Drive so everybody could access it easily) Last Open your connection before your operations with DataAdapter. Worked for me. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Moderators Robby Posted April 5, 2004 Moderators Posted April 5, 2004 I suggest creating your database objects at runtime instead of these design-time drag/drops or wizards. These samples will get you started http://samples.gotdotnet.com/QuickStart/winforms/default.aspx?url=/quickstart/winforms/doc/DataAccessPlaceHolder.aspx I understand that you want to eliminate repitition of code, if you design the application corectly you will have even less code then you do currently. Quote Visit...Bassic Software
Denaes Posted April 5, 2004 Author Posted April 5, 2004 I suggest creating your database objects at runtime instead of these design-time drag/drops or wizards. These samples will get you started http://samples.gotdotnet.com/QuickStart/winforms/default.aspx?url=/quickstart/winforms/doc/DataAccessPlaceHolder.aspx I understand that you want to eliminate repitition of code, if you design the application corectly you will have even less code then you do currently. Yeah, I spent about a week or three working on my dataAdaptors at one point, with about a thousand lines of code and 80% of it unmanaged, and thus no way of checking errors other than testing and reading it line by line. I have 8 tables, most relational, most having 10+ fields... it was a nightmare. Quote
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.