Here's a very condensed summary. For more information, pick
up a good book on ADO.NET. I recommend "Microsoft ADO.NET" from
Microsoft Press, but I'm admittedly biased.
The DataRow class lets you manage a set of changes to a row
of data, allowing you to access the current and original values
for each column. You can also check the DataRow object's
RowState property to determine the type of pending change stored
in the row - insert, update, delete.
You could use all of this information to build your own
update queries for each pending change. To simplify the process,
you might want to build a separate parameterized query for each
type of change - insert, update, and delete. These queries may
be standard SQL INSERT, UPDATE, and DELETE queries, or they may
be calls to stored procedures. Once you've created these
queries, you could process all modified rows and assign values
from the DataRow to the parameters of the appropriate query to
submit the pending change.
DataAdapters are designed to simplify this process. When
you call DataAdapter.Update and supply a DataTable, the
DataAdapter walks the rows and executes the query in the
appropriate Command property (InsertCommand, UpdateCommand,
DeleteCommand) based on each DataRow's RowState.
Parameters also simplify this process. Set the Parameter
object's SourceColumn and SourceVersion properties to bind the
parameter to a particular column and version of data in the
DataRow.
You can supply updating logic through code at run-time by
setting the DataAdapter's InsertCommand, UpdateCommand, and
DeleteCommand or you can use a CommandBuilder to generate this
logic for you dynamically at run-time. Using your own code will
give you better control and better performance. Relying on a
CommandBuilder requires less code, but requires that the
CommandBuilder ask the back-end for extended schema information
such as table and column names, key column information, etc. that
hampers performance.
Visual Studio .NET includes wizards that generate updating
logic for you. The wizard generates updating logic similar to
that of CommandBuilders, except that this logic is stored in your
code, resulting in better performance.
For code examples in C# and VB.NET using the SqlClient and
OLE DB .NET Data Providers, see "Updating the Database with a
DataAdapter and the DataSet" in the .NET Framework SDK under
.NET Framework SDK
Programming with the .NET Framework
Accessing Data with ADP.NET
Using .NET Data Providers to Access Data
I hope this information proves helpful.
David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.