reply to: be***@pocketrocks.com if possible:
I'm trying to set up a hierarchy system in this database where each row
can be related to a previous row. The problem is that when I go to
addTreeRow, it doesn't allow me to use Convert.DBNull for the childof
column, even though I have nilable set to true. (All parent nodes have
to be set to null, since they are not the child of any other row...
especially the very first row, which will have no other row to refer
to.) What is it I'm doing wrong... Does anyone know how to set up a
relationship between a row and one of it's table's earlier rows?
Something interesting to note, if I use a DataGrid, it works perfectly
fine. I just can't add rows using vb code - I can add as many rows with
a DataGrid as I want, and everything works perfectly. If I send it a
Nothing instead of Convert.DBNull, I get a better error (if you set it
up you'll see), it's an error in dataset1.vb, it looks like it's trying
to get an index from the value i'm sending - so it's crashing because it
can't get an index from a null value... Is there any possible way to get
around this? Is it a bug with the dataset compiler?
By the way, the reason I want to set this up is so that if I delete a
parent row, the cascade feature will delete all child rows, and so on.
attached is the VB.Net and XML Schema code i'm trying to use
vb code:
' crashes on this line if I use Convert.DBNull:
Dataset11.Tree.AddTreeRow("Title Test1", Convert.DBNull, Convert.DBNull)
Dataset11.Tree.AddTreeRow("Title Test2", Convert.DBNull, Convert.DBNull)
'Crashes in dataset1.vb if I use Nothing
Dataset11.Tree.AddTreeRow("Title Test3", Nothing, Nothing)
dataset code:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Dataset1" targetNamespace="http://tempuri.org/Dataset1.xsd" elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Dataset1.xsd" xmlns:mstns="http://tempuri.org/Dataset1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Dataset1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Tree">
<xs:complexType>
<xs:sequence>
<xs:element name="TreeID" type="xs:integer" minOccurs="0" msdata:AutoIncrement="true" msdata:AutoIncrementStep="1"
msdata:AutoIncrementSeed="1" />
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="ChildOf" type="xs:integer" minOccurs="0" nillable="true" />
<xs:element name="AttributeID" type="xs:integer" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Attributes">
<xs:complexType>
<xs:sequence>
<xs:element name="AttributeID" type="xs:integer" minOccurs="0" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="1"
msdata:AutoIncrementStep="1" />
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="Value" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="AttributeIDKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Attributes" />
<xs:field xpath="mstns:AttributeID" />
</xs:key>
<xs:key name="TreeIDKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:TreeID" />
</xs:key>
<xs:keyref name="AttributesTree" refer="AttributeIDKey" msdata:DeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:AttributeID" />
</xs:keyref>
<xs:keyref name="TreeTree" refer="TreeIDKey" msdata:DeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:ChildOf" />
</xs:keyref>
</xs:element>
</xs:schema>