Article ID: 313483 - Last Review: November 26, 2007 - Revision: 6.3 INFO: Roadmap for ADO.NET DataAdapter ObjectsThis article was previously published under Q313483 On This PageSUMMARY This article provides a roadmap to learn and master ADO.NET
DataAdapter objects. Roadmap articles provide links to useful information,
including online documentation, Microsoft Knowledge Base articles, and
Microsoft white papers, to help you learn about a Microsoft product or
technology. OverviewThe .NET data provider DataAdapter object wraps reading records into a DataSet object and updates the database from the DataSet. The DataAdapter manages Command and DataReader objects and simplifies the synchronization process. You can use the OleDbDataAdapter object to fill a DataSet from a Microsoft ActiveX Data Objects (ADO) Recordset or Record object.The DataAdapter object is just one way to transfer data between a database and a DataSet. If you need more control over the fill or update functionality, you can write a custom function to manage this process and manipulate the Command and the DataReader objects directly. For information on the Connection, the Command, and the DataReader classes, how to achieve .NET data provider independence, or how to write your own .NET data provider, click the article number below to view the article in the Microsoft Knowledge Base: 313480
(http://support.microsoft.com/kb/313480/EN-US/
)
INFO: Roadmap for .NET Data Providers
For information on the DataSet class, click the article number below to view the article in the
Microsoft Knowledge Base:
313485
(http://support.microsoft.com/kb/313485/EN-US/
)
INFO: Roadmap for ADO.NET DataSet, DataView, and DataViewManager Objects
For additional ADO.NET technology roadmap articles,
click the article number below to view the article in the Microsoft Knowledge
Base:
313590
(http://support.microsoft.com/kb/313590/EN-US/
)
INFO: Roadmap for ADO.NET
ArchitectureThe DataAdapter manages several Command objects:
How To Articles, Walkthroughs, and QuickStart SamplesMicrosoft Knowledge Base "How To" articles provide step-by-step instructions about how to accomplish specific tasks. Walkthroughs provide mini-tutorials that walk you through typical application development scenarios. QuickStart sample files provide code samples for your reference.The Visual Studio .NET Online Help topics, QuickStart sample files, walkthroughs, and Microsoft Knowledge Base articles in the sections to follow describe how to use the ADO.NET DataAdapter. QuickStart Samples QuickStart sample files are installed on your computer in one of two locations. If you install the QuickStart sample files as part of Visual Studio .NET, the sample files are located in the following folder:
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\QuickStart\...
If you install the QuickStart sample files as part of the .NET
development platform, the sample files are located in the following folder:
C:\Program Files\FrameworkSDK\Samples\QuickStart\...
Microsoft Knowledge Base ArticlesClick here to view a list of How To articles about ADO.NET DataAdapter objects
(http://support.microsoft.com/common/canned.aspx?r=d&h=ado.net+dataadapter+how+to+articles&ll=kbadonet&sz=kbhowto+and+(dataadapter+or+sqldataadapter+or+oledbdataadapter+or+odbcdataadapter))
Fill a DataSetYou can use the Fill method of the DataAdapter object to populate a DataSet with data. By default, the Fill method only supplies sufficient schema for read-only access to the data. To make updates, use one of the following methods:
Visual Studio .NET Online Help Documentation
Populating a DataSet from a DataAdapter QuickStart Sampleshttp://msdn2.microsoft.com/en-us/library/bh8kx08z(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/bh8kx08z(vs.71).aspx) Mapping .NET Data Provider Data Types to .NET Framework Data Types http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmappingnetdataproviderdatatypestonetframeworkdatatypes.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmappingnetdataproviderdatatypestonetframeworkdatatypes.asp) Adding Existing Constraints to a DataSet http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingexistingconstraintstodataset.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingexistingconstraintstodataset.asp)
Populate DataSet from Database If you installed the QuickStart samples on your computer, the
following subfolders contain additional samples:
http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/getdatafromdb.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/getdatafromdb.aspx) Loading a native ADO recordset into a DataSet http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/adorstodataset.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/adorstodataset.aspx) Use Data in Web Services http://samples.gotdotnet.com/quickstart/aspplus/doc/servicesanddata.aspx (http://samples.gotdotnet.com/quickstart/aspplus/doc/servicesanddata.aspx)
308072
(http://support.microsoft.com/kb/308072/EN-US/
)
HOW TO: Fill a DataSet from an Oracle Stored Procedure by Using the OLE DB .NET Data Provider with Visual Basic .NET
310101
(http://support.microsoft.com/kb/310101/EN-US/
)
HOW TO: Fill a DataSet from an Oracle Stored Procedure by Using the OLE DB .NET Data Provider with Visual C# .NET
310349
(http://support.microsoft.com/kb/310349/EN-US/
)
HOW TO: Use the OleDbDataAdapter to Fill a DataSet from an ADO Recordset in Visual Basic .NET
Update a Single TableIn a single table update, you call the Update method of the DataAdapter. By default, the Update method ends and raises a DBConcurrencyException exception when the method encounters a row that fails to update. A row may fail to update because of a concurrency violation or a constraint violation. To determine this, the DataAdapter examines the RowsAffected property that is returned by the command that you use to update the database.If the database does not return a RowsAffected property (for example, SQL Server SET NOCOUNT ON), DataAdapter assumes that all updates succeed. If you set the DataAdapter.ContinueUpdateOnError property to True, the DataAdapter tries to update all rows in the DataSet. Any errors that DataAdapter encounters are logged in the HasErrors and RowError properties of the DataRow objects that failed to update. Additional Notes
Updating the Database with a DataAdapter and the DataSet QuickStart Sampleshttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp) Retrieving Identity or Autonumber Values http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconretrievingidentityorautonumbervalues.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconretrievingidentityorautonumbervalues.asp) Optimistic Concurrency http://msdn2.microsoft.com/en-us/library/aa0416cz(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/aa0416cz(vs.71).aspx)
Update Database from a DataSet If you installed the QuickStart samples on your computer, the
following subfolders contain additional samples:
http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/updatedatafromdb.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/updatedatafromdb.aspx)
301248
(http://support.microsoft.com/kb/301248/EN-US/
)
HOW TO: Update a Database from a DataSet Object by Using Visual Basic .NET
307587
(http://support.microsoft.com/kb/307587/EN-US/
)
HOW TO: Update a Database from a DataSet Object by Using Visual C# .NET
308055
(http://support.microsoft.com/kb/308055/EN-US/
)
HOW TO: Update a SQL Server Database by Using the SqlDataAdapter Object in Visual Basic .NET
308507
(http://support.microsoft.com/kb/308507/EN-US/
)
HOW TO: Update a SQL Server Database by Using the SqlDataAdapter Object in Visual C# .NET
308510
(http://support.microsoft.com/kb/308510/EN-US/
)
HOW TO: Update a SQL Server Database by Using the SqlDataAdapter Object in Visual C++ .NET
310347
(http://support.microsoft.com/kb/310347/EN-US/
)
HOW TO: Fill a DataSet from a Data Source and Update Another Data Source by Using Visual Basic .NET
313028
(http://support.microsoft.com/kb/313028/EN-US/
)
HOW TO: Fill a DataSet from a Data Source and Update Another Data Source by Using Visual C# .NET
310351
(http://support.microsoft.com/kb/310351/EN-US/
)
HOW TO: Roll Back Updates After an Error When You Are Using a DataAdapter and a DataSet in ADO.NET and Visual Studio .NET
308042
(http://support.microsoft.com/kb/308042/EN-US/
)
HOW TO: Read and Write BLOB Data by Using ADO.NET with Visual Basic .NET
309158
(http://support.microsoft.com/kb/309158/EN-US/
)
HOW TO: Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
308056
(http://support.microsoft.com/kb/308056/EN-US/
)
HOW TO: Update Server Data Through a Web Service by Using ADO .NET and Visual Basic .NET
310143
(http://support.microsoft.com/kb/310143/EN-US/
)
HOW TO: Update Server Data Through a Web Service by Using ADO .NET and Visual C# .NET
Update Parent and Child RowsYou may find it more difficult to update both parent rows and child rows in a batch process than if you send updates back to the database as the updates occur. To avoid referential integrity problems on the database (you need one DataAdapter for each DataTable), you must update rows in the following order:
Additional Notes
Updating the Database with a DataAdapter and the DataSet http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp) Map Table and FieldWhen you use the DataAdapter.Fill and the Update methods, you specify a DataTable name. The DataTable name can differ from the database table name. In addition, the DataColumn name can differ from the column name on the database. Table mapping and field mapping are useful if you need to combine the data from two tables into one DataTable, especially if the field names do not match exactly.You can also create TableMapping and FieldMapping objects and add these objects to the DataAdapter.TableMappings collection. If you create these objects and add them to this collection, you do not have to explicitly specify the DataTable name during the Fill and the Update methods. If you add a DataAdapter component to your project in Visual Studio .NET, you can edit the TableMapping and FieldMapping objects by using property pages at design time. Visual Studio .NET Online Help Documentation
Setting Up DataTable and DataColumn Mappings MSDN Articles: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsettingupdatatabledatacolumnmappings.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsettingupdatatabledatacolumnmappings.asp) Table Mapping in ADO.NET
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/Data03142002.asp?frame=true)
Build Commands and ParametersWhen you use the SqlClient, the OleDb, and the Odbc .NET data providers, the commands can be SQL statements, SQL batches, or stored procedures. However, third-party .NET data providers may not support a command language.You can use one of the following methods to create the commands:
Using Parameters with a DataAdapter http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp) Input and Output Parameters, and Return Values http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinputoutputparametersreturnvalues.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinputoutputparametersreturnvalues.asp) Automatically Generated Commands http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconautomaticallygeneratedcommands.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconautomaticallygeneratedcommands.asp) Hook EventsThe DataAdapter raises the following three events:
Working with DataAdapter Events http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingremovingadonetproviderevents.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingremovingadonetproviderevents.asp) TroubleshootingIf you encounter problems and need answers to your questions, consult the MSDN newsgroups. The MSDN newsgroups are the best place to obtain answers to your questions. In the MSDN newsgroups, you can share your experiences with your peers or search the Microsoft Knowledge Base for articles about specific issues.
MSDN Newsgroups http://msdn.microsoft.com/newsgroups/ (http://msdn.microsoft.com/newsgroups/) Microsoft Knowledge Base http://support.microsoft.com/search/?adv=1 (http://support.microsoft.com/search/?adv=1) | Article Translations
|

Back to the top
