Good Database Programming

grip003

Well-known member
Joined
Sep 2, 2004
Messages
89
Location
North Carolina
This is an open thread to general thoughts and ideas about programming and interacting with a database.

I have been developing windows applications that rely on a database for the past few years. I am the only developer for the company I work for, so I dont have anyone to bounce ideas off of. I got some experience in college and graduate school, but I dont seem to have the time to just play around with different programming ideas. I seem to always need to be productive. So, I wanted to see how other programmers design and implement applications that communicate with a database.

Currently, I dont like to rely on binding any fields to a DataTable. I usually write a SetupFields function that loads the windows form fields with the appropriate information based on the current row in the datatable that the user has chosen. I allow the user to edit the fields, and when they click Save, then I validate all fields manually (make sure monetary fields are formatted correctly, etc.) and the create an UPDATE (or INSERT INTO for a new record) statement and send that to the database. Then I update the datatable locally and continue. Ive been wondering about writing classes for each table in the database and having each class be responsible for data retrieval and updates. Is this a good idea? What about validation? It seems like I am always writing validation/updating code to make changes in my database. Is there a better way to do this?

I would just like to hear other stories and comments about database programming from other experienced programmers. I program in C#, but I also have some legacy applications that were written in VB6. My applications seem to work, I just want to be a better programmer.
 
I was never tasked to do major db development. The small things I had to do were solved with my own object relational mapping. For larger projects I would stick with the pro tools. In java my coworkers would usually use hibernate.

Back in the days I didnt even think about a database abstraction layer but I would also hardcode constant values into my programs :D
 
grip003 said:
This is an open thread to general thoughts and ideas about programming and interacting with a database.

I have been developing windows applications that rely on a database for the past few years. I am the only developer for the company I work for, so I dont have anyone to bounce ideas off of. I got some experience in college and graduate school, but I dont seem to have the time to just play around with different programming ideas. I seem to always need to be productive. So, I wanted to see how other programmers design and implement applications that communicate with a database.

Currently, I dont like to rely on binding any fields to a DataTable. I usually write a SetupFields function that loads the windows form fields with the appropriate information based on the current row in the datatable that the user has chosen. I allow the user to edit the fields, and when they click Save, then I validate all fields manually (make sure monetary fields are formatted correctly, etc.) and the create an UPDATE (or INSERT INTO for a new record) statement and send that to the database. Then I update the datatable locally and continue. Ive been wondering about writing classes for each table in the database and having each class be responsible for data retrieval and updates. Is this a good idea? What about validation? It seems like I am always writing validation/updating code to make changes in my database. Is there a better way to do this?

I would just like to hear other stories and comments about database programming from other experienced programmers. I program in C#, but I also have some legacy applications that were written in VB6. My applications seem to work, I just want to be a better programmer.

I used to be an independent contractor, but now am doing exactly what youre doing, working as the only developer for a company that does a web-based app dependent on a database

I wrote, "The Dynamic Data Dictionary" as a discussion of how to use one Insert and Update statement for all of your inserts and updates. This isnt a buy my book post, that is just a point of reference.

I am a great believer in a data dictionary for ease of maintaining your fields and keeping code down. By writing a single statement that uses command parameters, and keeping the all of the field criteria in the datatable table, I cut down my overhead and my error trapping, and this means I write better code and write it faster.

Hope that helps
 
Thats an interesting idea. However, I like to do field validation where focus can be set to the field that is not validated and give a reason why. Do you take that into account for your data dictionary design?
 
Back
Top