Datasets - filling help

  • Thread starter Thread starter Pho
  • Start date Start date

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,336
Location
Derbyshire
I've managed to avoid touching datasets in the past and am having an awful time with them right now :o.

I need to manually fill the dataset and can't do it from SQL. It all works fine until I need to use a complextype.

I can generate sample XML from Visual Studio for this XSD which looks fine fine, I can use ReadXML() to read in XML in this format, and then WriteXML() it out to a file and again it is fine. I can't however find how to manually set the data.

My hacked together dataset fill looks something like this:
Code:
DataSet ds = new NewDataSet();
DataTable dt = ds.Tables["ReportData"];
DataRow dr = dt.NewRow();
dr["id"] = 999;
dr["children"] = {children}; // why can't I add children data? The column apparently doesn't exist
dt.Rows.Add(dr);

I can set the ID column fine. However, how do I gain access to the children column? There is a children table which is created, but I need to be able to nest the XML like below.


Schema:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:mstns="http://tempuri.org/XSDobject.xsd" xmlns="http://tempuri.org/XSDobject.xsd" elementFormDefault="qualified" targetNamespace="http://tempuri.org/XSDobject.xsd" id="XSDobject" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="DataSet">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element name="ReportData">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="id" type="xs:int" />
              <xs:element minOccurs="0" name="children">
                <xs:complexType>
                  <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="name" type="xs:string" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

I think what I'm essentially asking is how do I create a children data table, and add it to the row at the same time I add the id number etc?

I'm using Visual Studio 2008 if it's any help.

Thanks.
 
Back
Top Bottom