Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Good afternoon,

I have an XML and a corresponding XSD file generated from MS Access with a list of iso4217 currency codes and descriptions and a primary key.

My software reads the XML file (using DataSet.XmlRead()), and then generates a DataTable object of the table contained within the dataset (the table is called "iso4217").

My problem is: if I try to run the DataTable.Rows.Find() method, the debugger returns an error stating that there is no primary key. I have checked my XSD file and the primary key is there.

I have managed to get around the issue by setting the primary key of the generated DataTable programatically, however the rest of my solution relies very heavily on relational tables within XML files.

If there is something that I am missing, I want to get my head around now before I run into larger issues down the line.

For additional information, I have attached to two datafiles. Note: the XSD files was modified within Visual Studio:

XML:

XML
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="iso4217.xsd" generated="2010-07-30T15:26:56">
<iso4217>
<iso4217_id>152</iso4217_id>
<code>AED</code>
<description>UAE dirham</description>
</iso4217></dataroot>


XSD:
XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
  <xs:annotation>
    <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
      <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
        <Connections />
        <Tables />
        <Sources />
      </DataSource>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="iso4217" msprop:Generator_UserTableName="iso4217" msprop:Generator_RowDeletedName="iso4217RowDeleted" msprop:Generator_TableClassName="iso4217DataTable" msprop:Generator_RowChangedName="iso4217RowChanged" msprop:Generator_RowClassName="iso4217Row" msprop:Generator_RowChangingName="iso4217RowChanging" msprop:Generator_RowEvArgName="iso4217RowChangeEvent" msprop:Generator_RowEvHandlerName="iso4217RowChangeEventHandler" msprop:Generator_TablePropName="iso4217" msprop:Generator_TableVarName="tableiso4217" msprop:Generator_RowDeletingName="iso4217RowDeleting">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="iso4217_id" msdata:AutoIncrementSeed="1" msprop:Generator_UserColumnName="iso4217_id" msprop:Generator_ColumnPropNameInRow="iso4217_id" msprop:Generator_ColumnVarNameInTable="columniso4217_id" msprop:Generator_ColumnPropNameInTable="iso4217_idColumn" type="xs:int" />
        <xs:element name="code" msprop:Generator_UserColumnName="code" msprop:Generator_ColumnPropNameInRow="code" msprop:Generator_ColumnVarNameInTable="columncode" msprop:Generator_ColumnPropNameInTable="codeColumn" minOccurs="0">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:maxLength value="255" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
        <xs:element name="description" msprop:Generator_UserColumnName="description" msprop:Generator_ColumnPropNameInRow="description" msprop:Generator_ColumnVarNameInTable="columndescription" msprop:Generator_ColumnPropNameInTable="descriptionColumn" minOccurs="0">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:maxLength value="255" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="NewDataSet" msprop:Generator_DataSetName="NewDataSet">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="iso4217" />
      </xs:choice>
    </xs:complexType>
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//iso4217" />
      <xs:field xpath="iso4217_id" />
    </xs:unique>
  </xs:element>
</xs:schema>
Posted
Comments
Prasad Bansi Vagal 2-Aug-10 12:55pm    
Reason for my vote of 5
it was an easy question, aply simple logic.

there might be a primary key here but there might not be a primary key in actual table in sql, you have to check the key whether exists in sql table or not, if not again put primary key for respected coloumn by using alter table.......... to update the structure of the table and remember to again configure your dataset.

prasad :-D
 
Share this answer
 
Hi prasad,

Thanks for your reply.

I found in the end that my schema file was not being read into the dataset. I managed to do this by reading the XSD schema file seperately first, and then reading the XML data into the dataset. As the schema for both the XSD file and the XML file are the same, the datareading is fine, as long as I programmatically clear the dataset before rereading the XSD file.

However I am a little confused. My XML file clearly references the XSD schema file, should the DataSet.ReadXML() method find the schema file itself?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900