eramgarden Posted January 14, 2005 Posted January 14, 2005 Ok, my first C# WinForm .. I have a menu: File --> connect to Database So we want to connect to a database in one place, once in the beginning of the app ..Users enter the database name, userid and password... So, how should I do this? Write a "connection" class and pass the parameters to the class? Do the connection in the code behind of the form when the user clicks "connect" button?? what is the best way of doing this? Quote
RobEmDee Posted January 15, 2005 Posted January 15, 2005 (edited) I usually keep one internal sealed class that encapsulates all of the objects and code that the application needs to interact with the data source....I would suggest having a class similar to this in which you store the connection string you build from the user's input in a private static field. Then have a public static 'GetConnection()' method that returns a connection when needed. There are obviously many other things to consider in regards to security, exception handling/recovery, etc...but that is the basic gist of one way to handle data connections. Ok, my first C# WinForm .. I have a menu: File --> connect to Database So we want to connect to a database in one place, once in the beginning of the app ..Users enter the database name, userid and password... So, how should I do this? Write a "connection" class and pass the parameters to the class? Do the connection in the code behind of the form when the user clicks "connect" button?? what is the best way of doing this? Edited January 16, 2005 by RobEmDee Quote
eramgarden Posted January 17, 2005 Author Posted January 17, 2005 I'm new to C#..do u have an example of a class? searched online with not much luck.. 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.