Class interfere with database

skylight

New member
Joined
Oct 28, 2005
Messages
3
Just a thought:

I made some classes equivalent with database-tables, like students and courses. If a user changes the address of the student, it has to do an Update-query to update the database record.

Something like:
Code:
public class MainForm: System.Windows.Forms.Form
{
	Student student = new Student(name, id, address);
	...
	student.Address = something_else;
	// updatequery code here
}
Would it be any good to let the "Student" object interfere directly with the database?

Code:
public class MainForm: System.Windows.Forms.Form
{
	...
	Student student = new Student(name, id, address);
	...
	student.Address = something_else;
	student.UpdateRecord();
}

class Student
{
	...
	public void UpdateRecord()
	{
		//updatequery code here
	}
}

This way its much more clean in the main form code, and the database is only contacted in the "Student" class. Though, I havent seen this way of working before in examples, so there might be a catch. Any sugguestions why or why not using this method? I would also use it to delete and insert students.
 
Back
Top