protoculture Posted May 6, 2005 Posted May 6, 2005 I'm going to attempt to answer my own question. In a desktop application ( or any application for that matter ) should I be creating a class that does all my database input/output? Quote
Machaira Posted May 6, 2005 Posted May 6, 2005 And the answer is - it depends. :) MS has made data access so easy with .NET that it's sometimes not worth it to put a wrapper around it. For larger applications it might be useful, but for a simple app I wouldn't bother. Just my $.02. Quote Here's what I'm up to.
a_jam_sandwich Posted May 6, 2005 Posted May 6, 2005 I tend to code that way creating an API dll that deals with data into and out of the mail program but really it depends on how you want to code your application. For the smaller application the above is really overkill. But on a whole keeping all your database code in a class or module is a good way to code. Andy Quote Code today gone tomorrow!
protoculture Posted May 6, 2005 Author Posted May 6, 2005 Could someone let me know if this is going in the right direction? as you can see I've imported the System.Data class and everything underneath it, but when I build I get the following error: "Cannot find class SqlConnection" package JBE; import System.Data.*; /** * Used to control all database input / output */ public class dbcontrol { public dbcontrol() { /// TODO: Add Constructor Logic here } public void openDatabaseConnection() { String myConnectString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"; SqlConnection myConnection = new SqlConnection(myConnectString); myConnection.Open(); } public void closeDatabaseConnection() { } public boolean insertIntoDB() { return false; } public boolean updateDB() { return false; } public boolean selectDB() { return false; } } Quote
Machaira Posted May 6, 2005 Posted May 6, 2005 What happens if you change your import to: import System.Data.SqlClient; Quote Here's what I'm up to.
protoculture Posted May 6, 2005 Author Posted May 6, 2005 Thanks for everyones responses... Machaira: I get the following...when implementing your code Cannot find class 'System.Data.SqlClient' BTW- I'm using j#, that wouldn't have anything to do with it,would it? Quote
Machaira Posted May 6, 2005 Posted May 6, 2005 I thought you were using J#. I've never used it so I was taking a shot in the dark. How about: import System.Data.SqlClient.*; Quote Here's what I'm up to.
protoculture Posted May 6, 2005 Author Posted May 6, 2005 I thought you were using J#. I've never used it so I was taking a shot in the dark. How about: import System.Data.SqlClient.*; Hey that worked! Thanks... But how come this didn't work?... I thought all the sql classes were included with System.Data.* ? import System.Data.* Quote
Machaira Posted May 6, 2005 Posted May 6, 2005 Nope, they're in SqlClient. The "*" appears to only include the namespaces at that level, not the classes in those namespaces. Quote Here's what I'm up to.
rjonas Posted May 10, 2005 Posted May 10, 2005 I'm going to attempt to answer my own question. In a desktop application ( or any application for that matter ) should I be creating a class that does all my database input/output? I'd suggest your decision to do this should depend on the following 1) Are you likely to want to change your database, or the structure of the tables in it? If so, putting the logic into a class will make it easier to do this and mean you only need to change code in one place when you make database changes. 2) Do you do processing in the application, rather than the database. E.g. if you wanted to add an address to your DB that isn't formatted correctly, would you process this in the DB or in code before it gets that far. If you want to process this in code, you might want a separate class. 3) Are the "business concepts" the application understands different from the underlying database tables. If they are, having a separate class would make writing other parts of your application easier. I'd recommend the book "Patterns of Enterprise Application Architecture" by Martin Fowler if you want to read more about different ways of structuring your classes and the arguments for each. Richard Jonas http://www.btinternet.com/~rjonas Quote
Napivo1972 Posted May 10, 2005 Posted May 10, 2005 I have a question that has been burning for quite some time. It�s along these lines. When I wrap the database in a class should I use a dataset that can contain data from the entire database (and the relationships between tables) or break them up in logical blocks? Quote
mark007 Posted May 10, 2005 Posted May 10, 2005 I'm going to attempt to answer my own question. In a desktop application ( or any application for that matter ) should I be creating a class that does all my database input/output? Personally I have a standard class as this way I can use it in all applications. Further than this I create a interface IData that contains the methods I will need - such as connect, close, return disconnected data, return connected data, execute a query etc. All my db classes then implemenet this meaning I can change the database used in an application by changing one line from: Dim d as IData=New AccessData to: Dim d as IData=New MSSQLData etc. Also allows me to have applications where the data provider can be chosen by the client. :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code 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.