XML w/ string key read into Dataset changes row so item must be accessed as itemarray


E

Ed

I'm reading the following XML Schema and XML Data (see below) into a
Dataset and Datatables using this code:

dsConfig.ReadXmlSchema(XMLConfigSchema)
dsConfig.ReadXml(XMLConfigData)
dtCompInfo = dsConfig.Tables("ComputerInfo")
dtAccessInfo = dsConfig.Tables("AccessInfo")

I got an exception ("System.FormatException: Input string was not in a
correct format.") when I attempted to perform a Row.Find on the
dtCompInfo datatable using this code:
Dim oObjectToFind As Object
oObjectToFind = sDisplayName.ToString
drTemp = dtCompInfo.Rows.Find(oObjectToFind)

Upon further inspection, I noticed the data in the row of the
datatable was placed into an ItemArray instead of just a item of type
string.
From the Immediate window:

?dtCompInfo.Rows(0).Item
Overload resolution failed because no accessible 'Item' accepts this
number of arguments.
?dtCompInfo.Rows(0).ItemArray
{Length=2}
(0): "BaseStation"
(1): 0 {Integer}

If I modify the object to search for 0 instead
oObjectToFind = 0
the Find() works. This appears to be because the Find() method seems
to want to search on the ItemArray(1) which is an integer.

Why is this happening? The only data here should be the a single
string (a single item, not an item array)...it appears to be adding
its own indexing and not allowing me to search on the key I specified
(as a string) in the XML schema and data.

Any help would be appreciated.

Thanks,

-Ed

XML schema:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="HC_Computers"
targetNamespace="http://tempuri.org/HC_Computers.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/HC_Computers.xsd"
xmlns:mstns="http://tempuri.org/HC_Computers.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="ComputerAccess">
<xs:sequence>
<xs:element name="IPorName" type="xs:string" />
<xs:element name="ID" type="xs:string" />
<xs:element name="PW" type="xs:string" />
<xs:element name="Domain" type="xs:string" />
<xs:element name="DisplayName" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="Computers">
<xs:complexType>
<xs:sequence>
<xs:element name="ComputerInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="DisplayName" type="xs:string" />
<xs:element name="AccessInfo" type="ComputerAccess" />
</xs:sequence>
</xs:complexType>
<xs:key name="DisplayName">
<xs:selector xpath="." />
<xs:field xpath="mstns:DisplayName" />
</xs:key>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="AccessKey">
<xs:selector xpath=".//mstns:AccessInfo" />
<xs:field xpath="mstns:DisplayName" />
</xs:key>
</xs:element>
</xs:schema>

XML data:
<?xml version="1.0" standalone="yes"?>
<Computers xmlns="http://tempuri.org/HC_Computers.xsd">
<ComputerInfo>
<DisplayName>BaseStation</DisplayName>
<AccessInfo>
<IPorName>BaseStation</IPorName>
<ID>USERID</ID>
<PW>PASSWORD</PW>
<Domain></Domain>
<DisplayName>BaseStation</DisplayName>
</AccessInfo>
</ComputerInfo>
<ComputerInfo>
<DisplayName>WS2003</DisplayName>
<AccessInfo>
<IPorName>WS2003</IPorName>
<ID>USERID</ID>
<PW>PASSWORD</PW>
<Domain></Domain>
<DisplayName>WS2003</DisplayName>
</AccessInfo>
</ComputerInfo>
</Computers>
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top