307989 PRB: Visual C # .NET application lacks specified sequence data set column mapping to raise InvalidOperationException (fro

xiaoxiao2021-03-06  77

The release number of this article has been CHS307989

For Microsoft Visual Basic .NET versions of this article, see

307170.

This article references the following Microsoft .NET Framework Class Bank Name Space:

System.Data.COMMON

System.Data.Oledb

Symptoms When using a data set column mapping in ADO.NET,

MISSINGMAPPINGAATION attribute is set to

Error, but missing the column map you specify, the InvalidOperationException exception will be triggered.

Solution To resolve this issue, make sure that the column map you specify exists. See "More Information" section for checking the specified column mapping exists.

More information

Steps to reproduce the phenomenon

Start Microsoft Visual Studio .NET. Create a Windows application project in Visual C # .NET. The Form1 is added to the project by default. Make sure your project contains a reference to System.Data namespace, if not included, add a reference to this namespace. Place a Command button on Form1 and change its Name property to btntest. Using the USING statement for System, System.Data, System.Data.Common, and System.Data.Oledb names, this is not required to define the declarations in these namespaces in the later code. Using system;

Using system.data;

Using system.data.common;

Using system.data.oledb; Switch to Forms view, then double-click the button to add a 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 ();

.

// if (myDataadapter.tablemappings.contains ("categories1")))

{

mynewmapping1 =

DataTableMappingCollection.getTableMappingByschemaAction

(MyDataAdapter.tablemappings, "categories1", "",

MissingmappingAction.error);

} Save the project. On the Debug menu, click Start, and then run your project. Click this button. Note that you will receive an exception mentioned above. To resolve this issue, cancel the "IF" loop in the code sample, and then run the project. Because the "IF" loop checks if the specified column map exists, you will not receive the exception. Refer to more information about ADO.NET objects and syntax, see the following Microsoft .NET Framework Software Development Kit (SDK) documentation:

Use ADO.NET access data http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaccessingDatawithadonet.asp

The information in this article applies to:

Microsoft ADO.NET (provided with .NET Frame) Microsoft Visual C # .NET (2002)

Reserved: 2002-6-17 (1.0) Keyword Kbdsupport KBGRPDSMDAC KBGRPDSVBDB KBOLEDB KBPRB KBSYSTEMDATA KB307989

转载请注明原文地址:https://www.9cbs.com/read-108926.html

New Post(0)