This example updates an Empoyee without first loading it.
Code:
Employees emp = new Employees();
emp.AddNew(); // Merely creates the DataTable = RowState = Added
emp.EmployeeID = 1;
emp.AcceptChanges(); // Mark the record as DataRowState.Unchanged
emp.FirstName = "Direct"; // Any column change marks the record as DataRowState.Modified
emp.LastName = "Updates";
emp.Save();
The perferred way is still:
Code:
Employee emp = new Employee();
emp.LoadByPrimaryKey(1);
emp.FirstName = "Direct";
emp.LastName = "Updates";
emp.Save();
This is the perferred way for for several reasons. First, down the road you
encounter bottlenecks, but discover that the solution is to switch from your
default of DynamicSQL to StoredProcedure. If you used the preferred approach you
have a 1 line change to your config file and you are good to go. The
non-preferred method doesn't allow for the use of stored procedures and relies
entirely on dynamic sql. Also, and more importanly, you have no concurrency
handling possibiliites in the non-preferred sample.