Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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?

 

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 it's much more clean in the main form code, and the database is only contacted in the "Student" class. Though, I haven't 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.

Posted
I can't see why that wouldn't work assuming the Student objects have access to the database. I.e its not a member of MainForm.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...