Nested tables - How do you add a new row to a nested table? (codeattached)

B

Benny Raymond

I have a dataset setup with a main table that has some information in it
along with an element that is a nested table so that I can store rows of
history information for that one row in the main table. This all works
fine in a datagrid I can add rows to the nested table of any of my
customer rows... However in code I can't figure out how to do the same
thing... the only function I can find is "GetHistoryRows"... I'm
completely lost here - how would I go about adding a history row?

Below is a simple version of the schema that i'm using:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="debug" targetNamespace="http://tempuri.org/debug.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/debug.xsd"
xmlns:mstns="http://tempuri.org/debug.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="debug" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="customers">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="history">
<xs:complexType>
<xs:sequence>
<xs:element name="date" type="xs:dateTime" minOccurs="0" />
<xs:element name="description" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
 
B

Bruce Wood

If you're storing the data in a DataSet then you need a second
DataTable, say called CustomerHistory, that has a foreign key relation
with your Customer table, in a parent / child relationship, where
Customer is the parent, and CustomerHistory is the child table.

Effectively, every row in the CustomerHistory table will have some sort
of identifier to indicate to which Customer it belongs. The table will
store history for all customers, but you'll know to which Customer a
given row of CustomerHistory belongs by looking at that identifier.

You can also enforce this relationship in ADO.NET using a
ForeignKeyConstraint.
 

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