KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So, I am a fairly new programmer working towards an undergraduate Comp Sci degree with a very small amount of work experience. In looking for internship-type jobs for my program, I have noticed that what I've heard from several profs -- "working with databases makes up 90% of all modern computer science jobs" -- looks like it is actually true. However, my program doesn't really have any courses with databases until 3rd year, so I'm trying to at least learn some things myself in the mean time. I've seen very little on SO and the internet in general for somebody like myself. There seem to be tons of tutorials on the mechanics of how to read and write data in a database, but little on the associated best practices. To demonstrate what I am talking about, and to help get across my actual question, here is what can easily be found on the internet : public static void Main () { using (var conn = new OdbcConnection()) { var command = new OdbcCommand(); command.Connection = conn; command.CommandText = "SELECT * FROM Customer WHERE id = 1"; var dbAdapter = new OdbcDataAdapter(); dbAdapter.SelectCommand = command; var results = new DataTable(); dbAdapter.Fill(results); } // then you would do something like string customerName = (string) results.Rows[0]["name"]; } And so forth. This is pretty simple to understand but obviously full of problems. I started out with code like this and quickly started saying things like "well it seems dumb to just have SQL all over the place, I should put all that in a constants file." And then I realized that it was silly to have those same lines of code all over the place and just put all that stuff with connection objects etc inside a method: public DataTable GetTableFromDB (string sql) { // code similar to firs
Tags (comma-separated)
Save Edits
Cancel