Microsoft Knowledge Base Email Alertz

KBAlertz.com: When you use DataSet column mapping in ADO.NET, an

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 307989 - Last Review: May 13, 2007 - Revision: 2.6

DataSet column mapping throws an InvalidOperationException exception when the specified column is missing in a Visual C# application

This article was previously published under Q307989
For a Microsoft Visual Basic .NET version of this article, see 307170  (http://kbalertz.com/Feedback.aspx?kbNumber=307170/EN-US/ ) .

This article refers to the following Microsoft .NET Framework Class Library namespaces:
  • System.Data.Common
  • System.Data.OleDb

On This Page

SYMPTOMS

When you use DataSet column mapping in ADO.NET, an InvalidOperationException exception is thrown if the MissingMappingAction property is set to Error, and if the column mapping that you specify is missing.

RESOLUTION

To resolve this problem, ensure that the column mapping that you specify exists. Refer to the "More Information" section for code that checks whether the specified column mapping exists.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET.
  2. Create a new Windows Application project in Visual C# .NET or Visual C# 2005. Form1 is added to the project by default.
  3. Make sure that your project contains a reference to the System.Data namespace, and add a reference to this namespace if it does not.
  4. Place a Command button on Form1, and change its Name property to btnTest.
  5. Use the using statement on the System, System.Data, System.Data.Common, and System.Data.OleDb namespaces so that you are not required to qualify declarations in those namespaces later in your code.
    using System;
    using System.Data;
    using System.Data.Common;
    using System.Data.OleDb; 
    					
  6. Switch to Form view, and then double-click the button to add the Click event handler. Add the following code to the handler:
        OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
        myDataAdapter.TableMappings.Add("Categories", "DataCategories");
    
        String myMessage;
        myMessage = "Table Mappings: \n"; 
        System.Int32 i;
        for (i=0 ; i <= myDataAdapter.TableMappings.Count -1 ; i++)
        {
            myMessage += i.ToString() + " " 
    	    + myDataAdapter.TableMappings[i].ToString();
        }
        System.Diagnostics.Debug.WriteLine(myMessage);
    
        DataTableMapping myNewMapping1 = new DataTableMapping();
        //Uncomment the following if statement to check if the specified column mapping exists.
        //if (myDataAdapter.TableMappings.Contains("Categories1"))
        {
            myNewMapping1 = 
                DataTableMappingCollection.GetTableMappingBySchemaAction 
                (myDataAdapter.TableMappings, "Categories1", "",
                MissingMappingAction.Error);
        }
    					
  7. Save your project. On the Debug menu, click Start, and then run your project.
  8. Click the button. Notice that you receive the above-mentioned exception.
  9. To resolve this problem, uncomment the "if" loop in the sample code, and then run the project again. Because the "if" loop checks whether the specified column mapping exists, you no longer receive the exception.

REFERENCES

For more information on ADO.NET objects and syntax, refer to the following Microsoft .NET Framework Software Development Kit (SDK) documentation:
Accessing Data with ADO.NET
http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx)

APPLIES TO
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET 2.0
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# 2005
Keywords: 
kbtshoot kberrmsg kbnofix kbprb kbsystemdata KB307989
       

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