Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 310128 - Last Review: February 22, 2007 - Revision: 2.1
INFO: When to Use FillSchema and MissingSchemaAction with the DataAdapter in ADO.NET
This article was previously published under Q310128
SUMMARY
The
DataAdapter object is optimized for read-only scenarios by default. The
Fill method only retrieves the amount of schema that is necessary to populate a
DataSet object. To obtain the additional schema that are necessary to update or validate
DataSet objects, use one of the following methods for
DataSet objects that are populated by the
DataAdapater:
- Use the FillSchema method of the DataAdapter.
- Use the AddWithKey enumeration for the MissingSchemaAction property of the DataAdapter.
This article describes how to choose between these two methods when you want to populate updateable
DataSet objects with the
DataAdapter.
MORE INFORMATION
Setting the
MissingSchemaAction property of the
DataAdapter to
AddWithKey is analogous to using the
DataAdapter.FillSchema method. Both methods add schema information about primary keys,
AutoIncrement fields, nullable fields, and unique indexes.
When to Use DataAdapter's FillSchema Method
Use the
FillSchema method of the
DataAdapter if you will be reading the same data multiple times. If you use
MissingSchemaAction.AddWithKey, the schema is fetched with every call to the
DataAdapter.Fill method.
When to Use DataAdapter's MissingSchemaAction.AddWithKey Method
- Use DataAdapter.MissingSchemaAction.AddWithKey when you are retrieving multiple result sets in a single batch. If you are using the OLE DB .NET Data Provider, the DataAdapter.FillSchema method retrieves schema information for only the first result set when there are multiple SQL SELECT commands in a batch.
- Use DataAdapter.MissingSchemaAction.AddWithKey if you are calling DataAdapter.Fill just one time for a DataSet.
When Not to Use Either FillSchema or MissingSchemaAction.AddWithKey
- Do not use either method when you are obtaining a read-only DataSet to avoid adding unnecessary overhead.
- Do not use either method when you use the Visual Design Tools to generate a DataSet because the code for updateability is already incorporated into the tool-generated DataSet class.
- Do not use either method when you load a DataSet from XML if you want the DataSet to use the XML schema instead of a generated schema.
REFERENCES
For more information, see the following topics in the Microsoft Visual Studio .NET Help documentation:
For additional information, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
301248Â
(http://kbalertz.com/Feedback.aspx?kbNumber=301248/EN-US/
)
HOW TO: Update a Database from a DataSet Object by Using Visual Basic .NET
301216Â
(http://kbalertz.com/Feedback.aspx?kbNumber=301216/EN-US/
)
HOW TO: Populate a DataSet Object from a Database by Using Visual Basic .NET
APPLIES TO
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft ADO.NET 1.1
| kbdatabase kbinfo KB310128 |
Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please