DataRelation nested Framework 1.1

  • Thread starter Thread starter marc
  • Start date Start date
M

marc

I am getting the following error when running this sample code on .Net Framework 1.1, but this runs fine with .Net Framework 1.0. I have highlighted (in red) the line of code that the exception is coming from. Any ideas?:

"A column named 'address' already belongs to this DataTable: cannot set a nested table name to the same name."



Private Sub Test()



Dim ods As DataSet

Dim sXml As String

Dim oParentCol As DataColumn

Dim oChildCol As DataColumn

Dim oRelation As DataRelation

Dim oStrReader As StringReader



Try

ods = New DataSet

sXml = "<root><person id=""1"" name=""bob""><address personid=""1"" street=""123 Main Street"" /></person></root>"

oStrReader = New StringReader(sXml)

ods.ReadXml(oStrReader, XmlReadMode.InferSchema)



ods.Relations.Remove("person_address")



oParentCol = ods.Tables("person").Columns("id")

oChildCol = ods.Tables("address").Columns("personid")

oRelation = New DataRelation("person_address", oParentCol, oChildCol, True)

oRelation.Nested = True

ods.Relations.Add(oRelation)

Catch ex As Exception

TextBox1.Text = ex.Message

End Try



End Sub
 
I just received a response from a contact at Microsoft that this is a known bug in Framework 1.1. Can anyone offer a workaround to achieve the same result? Basically I need to read xml into a dataset and create a nested relationship between two of the tables.
I am getting the following error when running this sample code on ..Net Framework 1.1, but this runs fine with .Net Framework 1.0. I have highlighted (in red) the line of code that the exception is coming from. Any ideas?:

"A column named 'address' already belongs to this DataTable: cannot set a nested table name to the same name."



Private Sub Test()



Dim ods As DataSet

Dim sXml As String

Dim oParentCol As DataColumn

Dim oChildCol As DataColumn

Dim oRelation As DataRelation

Dim oStrReader As StringReader



Try

ods = New DataSet

sXml = "<root><person id=""1"" name=""bob""><address personid=""1"" street=""123 Main Street"" /></person></root>"

oStrReader = New StringReader(sXml)

ods.ReadXml(oStrReader, XmlReadMode.InferSchema)



ods.Relations.Remove("person_address")



oParentCol = ods.Tables("person").Columns("id")

oChildCol = ods.Tables("address").Columns("personid")

oRelation = New DataRelation("person_address", oParentCol, oChildCol, True)

oRelation.Nested = True

ods.Relations.Add(oRelation)

Catch ex As Exception

TextBox1.Text = ex.Message

End Try



End Sub
 
One more piece of information, if I read in xml that doesn't have a nested structure then I create the nested relationship it works fine. The problem is that if I read in Xml with a nested structure and create a nested datarelation.

Example:

<root>
<person id="1" name="bob"/>
<address personid="1" street="123 Main Street" />
</root>

When I read in this particular xml and create the nested relationship on person.id and address.personid I don't get the error. But if the xml is:

<root>
<person id="1" name="bob">
<address personid="1" street="123 Main Street" />
</person>
</root>

and I create the same relationship I get the error. This happens whether or not I remove the datarelation that is automatically created by Ado.net when reading xml into the dataset.
I just received a response from a contact at Microsoft that this is a known bug in Framework 1.1. Can anyone offer a workaround to achieve the same result? Basically I need to read xml into a dataset and create a nested relationship between two of the tables.
I am getting the following error when running this sample code on ..Net Framework 1.1, but this runs fine with .Net Framework 1.0. I have highlighted (in red) the line of code that the exception is coming from. Any ideas?:

"A column named 'address' already belongs to this DataTable: cannot set a nested table name to the same name."



Private Sub Test()



Dim ods As DataSet

Dim sXml As String

Dim oParentCol As DataColumn

Dim oChildCol As DataColumn

Dim oRelation As DataRelation

Dim oStrReader As StringReader



Try

ods = New DataSet

sXml = "<root><person id=""1"" name=""bob""><address personid=""1"" street=""123 Main Street"" /></person></root>"

oStrReader = New StringReader(sXml)

ods.ReadXml(oStrReader, XmlReadMode.InferSchema)



ods.Relations.Remove("person_address")



oParentCol = ods.Tables("person").Columns("id")

oChildCol = ods.Tables("address").Columns("personid")

oRelation = New DataRelation("person_address", oParentCol, oChildCol, True)

oRelation.Nested = True

ods.Relations.Add(oRelation)

Catch ex As Exception

TextBox1.Text = ex.Message

End Try



End Sub
 
Back
Top