By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

How? Add a row will a null value in a column that requires a keyrefrence?

P: n/a
reply to: be*** 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="" elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="" xmlns:mstns=""
xmlns:xs="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Dataset1" msdata:IsDataSet="true">
<xs:choice maxOccurs="unbounded">
<xs:element name="Tree">
<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:element name="Attributes">
<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:key name="AttributeIDKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Attributes" />
<xs:field xpath="mstns:AttributeID" />
<xs:key name="TreeIDKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:TreeID" />
<xs:keyref name="AttributesTree" refer="AttributeIDKey" msdata:DeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:AttributeID" />
<xs:keyref name="TreeTree" refer="TreeIDKey" msdata:DeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Tree" />
<xs:field xpath="mstns:ChildOf" />
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.