PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

Differnt behavior of ADO.Net Relation.Nested under 1.1

 
 
Butch
Guest
Posts: n/a
 
      9th Jul 2003
I have an example from MSDN that seems to have worked
under 1.0. It does not under 1.1.
This is the survey example found at:

http://msdn.microsoft.com/library/default.asp
url=/library/en-us/dnaspp/html/surveysample2.asp

The write up found there explains how and why the author
must change from code some of the properties of her
strongly typed dataset. Her code apparently runs fine on
1.0 but will error at rel.Nested = true when using Net
Framework V1.1.

Here is her code:

Public Class ResponseDataSet
Inherits BaseResponseDataSet

Public Sub New()
MyBase.New()
AdjustQuestionPrimaryKey()
End Sub

Protected Sub New(ByVal info As SerializationInfo,_
ByVal context As StreamingContext)
MyBase.New(info, context)
AdjustQuestionPrimaryKey()
End Sub

' This method sets the primary key for the Question
table
' to the Id column drawn from the original data
' rather than the Id column created by the
autogenerated code
Public Sub AdjustQuestionPrimaryKey()

Answer.Constraints.Remove("Question_Answer")
Question.Constraints.Clear()

Question.PrimaryKey = New DataColumn()
{Question.Columns("Id")}

Dim fkc As ForeignKeyConstraint
fkc = New ForeignKeyConstraint("Question_Answer",_
New DataColumn() {Question.Columns
("Id")},_
New DataColumn(){Answer.Columns
("Question_Id")})
fkc.AcceptRejectRule = AcceptRejectRule.None
fkc.DeleteRule = Rule.Cascade
fkc.UpdateRule = Rule.Cascade
Answer.Constraints.Add(fkc)

Relations.Remove("Question_Answer")
Dim rel As DataRelation = New DataRelation
("Question_Answer",_
New DataColumn() {Question.Columns
("Id")},_
New DataColumn() {Answer.Columns
("Question_Id")},_
False)
rel.Nested = True
Relations.Add(rel)
End Sub
End Class

Here is the error thrown when hitting the rel.Nested =
True line:

A column named 'Answer' already belongs to this
DataTable: cannot set a nested table name to the same
name.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.Data.DuplicateNameException: A
column named 'Answer' already belongs to this DataTable:
cannot set a nested table name to the same name.


 
Reply With Quote
 
 
 
 
Scot Rose [MSFT]
Guest
Posts: n/a
 
      10th Jul 2003
There may be something wrong with the XML, The error message is pretty specific that a tnested table is trying to be named the same as a column name and that this cannot be
done... The following code does not reproduce any errors and outputs a properly nested XML output...

Dim nwindConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection("Data Source=MyServer;uid=sa;pwd=Password;Initial
Catalog=Northwind;")
Dim custDA As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter("SELECT CustomerID, CompanyName FROM Customers",
nwindConn)
Dim orderDA As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter("SELECT OrderID, CustomerID, OrderDate FROM Orders",
nwindConn)

nwindConn.Open()

Dim custDS As DataSet = New DataSet("CustomerOrders")
custDA.Fill(custDS, "Customers")
orderDA.Fill(custDS, "Orders")

nwindConn.Close()

Dim custOrderRel As DataRelation = custDS.Relations.Add("CustOrders", custDS.Tables("Customers").Columns("CustomerID"), custDS.Tables("Orders").Columns
("CustomerID"))
custOrderRel.Nested = True
custDS.WriteXml("D:\MyTest.xml")

so it appears that Relation.Nested is working properly in 1.1...

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (E-Mail Removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
>Content-Class: urn:content-classes:message
>From: "Butch" <(E-Mail Removed)>
>Sender: "Butch" <(E-Mail Removed)>
>Subject: Differnt behavior of ADO.Net Relation.Nested under 1.1
>Date: Wed, 9 Jul 2003 08:31:23 -0700
>Lines: 82
>Message-ID: <008e01c3462f$277dd0f0$(E-Mail Removed)>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>Thread-Index: AcNGLyd9Sk9FnLumQI22EJeCaBbujg==
>Newsgroups: microsoft.public.dotnet.framework.adonet
>NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!cpmsftngxa09.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:55253
>X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
>
>I have an example from MSDN that seems to have worked
>under 1.0. It does not under 1.1.
>This is the survey example found at:
>
>http://msdn.microsoft.com/library/default.asp?
>url=/library/en-us/dnaspp/html/surveysample2.asp
>
>The write up found there explains how and why the author
>must change from code some of the properties of her
>strongly typed dataset. Her code apparently runs fine on
>1.0 but will error at rel.Nested = true when using Net
>Framework V1.1.
>
>Here is her code:
>
>Public Class ResponseDataSet
> Inherits BaseResponseDataSet
>
> Public Sub New()
> MyBase.New()
> AdjustQuestionPrimaryKey()
> End Sub
>
> Protected Sub New(ByVal info As SerializationInfo,_
> ByVal context As StreamingContext)
> MyBase.New(info, context)
> AdjustQuestionPrimaryKey()
> End Sub
>
> ' This method sets the primary key for the Question
>table
> ' to the Id column drawn from the original data
> ' rather than the Id column created by the
>autogenerated code
> Public Sub AdjustQuestionPrimaryKey()
>
> Answer.Constraints.Remove("Question_Answer")
> Question.Constraints.Clear()
>
> Question.PrimaryKey = New DataColumn()
>{Question.Columns("Id")}
>
> Dim fkc As ForeignKeyConstraint
> fkc = New ForeignKeyConstraint("Question_Answer",_
> New DataColumn() {Question.Columns
>("Id")},_
> New DataColumn(){Answer.Columns
>("Question_Id")})
> fkc.AcceptRejectRule = AcceptRejectRule.None
> fkc.DeleteRule = Rule.Cascade
> fkc.UpdateRule = Rule.Cascade
> Answer.Constraints.Add(fkc)
>
> Relations.Remove("Question_Answer")
> Dim rel As DataRelation = New DataRelation
>("Question_Answer",_
> New DataColumn() {Question.Columns
>("Id")},_
> New DataColumn() {Answer.Columns
>("Question_Id")},_
> False)
> rel.Nested = True
> Relations.Add(rel)
> End Sub
>End Class
>
>Here is the error thrown when hitting the rel.Nested =
>True line:
>
>A column named 'Answer' already belongs to this
>DataTable: cannot set a nested table name to the same
>name.
>Description: An unhandled exception occurred during the
>execution of the current web request. Please review the
>stack trace for more information about the error and
>where it originated in the code.
>
>Exception Details: System.Data.DuplicateNameException: A
>column named 'Answer' already belongs to this DataTable:
>cannot set a nested table name to the same name.
>
>
>



 
Reply With Quote
 
Butch
Guest
Posts: n/a
 
      10th Jul 2003
OK, something in xml then. I am stuck. Why did code
execute as expected under vs net 2002 with framework 1.0.
and now not behave correctly ? The only change here is
new framework.
I'd like to make the sample work. Much of the
functionality is usefull to me. I have seen some others
with this problem on other news groups.
Do you know if authors of msdn article are aware that
code is broken ?
The code is broken ? You reproduced error ?
Anyway thanks for help so far.

>-----Original Message-----
>There may be something wrong with the XML, The error

message is pretty specific that a tnested table is trying
to be named the same as a column name and that this
cannot be
>done... The following code does not reproduce any errors

and outputs a properly nested XML output...
>
> Dim nwindConn As

System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection("Data
Source=MyServer;uid=sa;pwd=Password;Initial
>Catalog=Northwind;")
> Dim custDA As

System.Data.SqlClient.SqlDataAdapter = New
System.Data.SqlClient.SqlDataAdapter("SELECT CustomerID,
CompanyName FROM Customers",
>nwindConn)
> Dim orderDA As

System.Data.SqlClient.SqlDataAdapter = New
System.Data.SqlClient.SqlDataAdapter("SELECT OrderID,
CustomerID, OrderDate FROM Orders",
>nwindConn)
>
> nwindConn.Open()
>
> Dim custDS As DataSet = New DataSet

("CustomerOrders")
> custDA.Fill(custDS, "Customers")
> orderDA.Fill(custDS, "Orders")
>
> nwindConn.Close()
>
> Dim custOrderRel As DataRelation =

custDS.Relations.Add("CustOrders", custDS.Tables
("Customers").Columns("CustomerID"), custDS.Tables
("Orders").Columns
>("CustomerID"))
> custOrderRel.Nested = True
> custDS.WriteXml("D:\MyTest.xml")
>
>so it appears that Relation.Nested is working properly

in 1.1...
>
>Want to know more? Check out the MSDN Library at

http://msdn.microsoft.com or the Microsoft Knowledge
Base at http://support.microsoft.com
>
>Scot Rose, MCSD
>Microsoft Visual Basic Developer Support
>Email : (E-Mail Removed) <Remove word online.

from address>
>
>This posting is provided "AS IS", with no warranties,

and confers no rights.
>
>
>
>
>--------------------
>>Content-Class: urn:content-classes:message
>>From: "Butch" <(E-Mail Removed)>
>>Sender: "Butch" <(E-Mail Removed)>
>>Subject: Differnt behavior of ADO.Net Relation.Nested

under 1.1
>>Date: Wed, 9 Jul 2003 08:31:23 -0700
>>Lines: 82
>>Message-ID: <008e01c3462f$277dd0f0$(E-Mail Removed)>
>>MIME-Version: 1.0
>>Content-Type: text/plain;
>> charset="iso-8859-1"
>>Content-Transfer-Encoding: 7bit
>>X-Newsreader: Microsoft CDO for Windows 2000
>>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>>Thread-Index: AcNGLyd9Sk9FnLumQI22EJeCaBbujg==
>>Newsgroups: microsoft.public.dotnet.framework.adonet
>>NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
>>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!

cpmsftngxa09.phx.gbl
>>Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.adonet:55253
>>X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
>>
>>I have an example from MSDN that seems to have worked
>>under 1.0. It does not under 1.1.
>>This is the survey example found at:
>>
>>http://msdn.microsoft.com/library/default.asp?
>>url=/library/en-us/dnaspp/html/surveysample2.asp
>>
>>The write up found there explains how and why the

author
>>must change from code some of the properties of her
>>strongly typed dataset. Her code apparently runs fine

on
>>1.0 but will error at rel.Nested = true when using Net
>>Framework V1.1.
>>
>>Here is her code:
>>
>>Public Class ResponseDataSet
>> Inherits BaseResponseDataSet
>>
>> Public Sub New()
>> MyBase.New()
>> AdjustQuestionPrimaryKey()
>> End Sub
>>
>> Protected Sub New(ByVal info As SerializationInfo,_
>> ByVal context As StreamingContext)
>> MyBase.New(info, context)
>> AdjustQuestionPrimaryKey()
>> End Sub
>>
>> ' This method sets the primary key for the Question
>>table
>> ' to the Id column drawn from the original data
>> ' rather than the Id column created by the
>>autogenerated code
>> Public Sub AdjustQuestionPrimaryKey()
>>
>> Answer.Constraints.Remove("Question_Answer")
>> Question.Constraints.Clear()
>>
>> Question.PrimaryKey = New DataColumn()
>>{Question.Columns("Id")}
>>
>> Dim fkc As ForeignKeyConstraint
>> fkc = New ForeignKeyConstraint

("Question_Answer",_
>> New DataColumn() {Question.Columns
>>("Id")},_
>> New DataColumn(){Answer.Columns
>>("Question_Id")})
>> fkc.AcceptRejectRule = AcceptRejectRule.None
>> fkc.DeleteRule = Rule.Cascade
>> fkc.UpdateRule = Rule.Cascade
>> Answer.Constraints.Add(fkc)
>>
>> Relations.Remove("Question_Answer")
>> Dim rel As DataRelation = New DataRelation
>>("Question_Answer",_
>> New DataColumn() {Question.Columns
>>("Id")},_
>> New DataColumn() {Answer.Columns
>>("Question_Id")},_
>> False)
>> rel.Nested = True
>> Relations.Add(rel)
>> End Sub
>>End Class
>>
>>Here is the error thrown when hitting the rel.Nested =
>>True line:
>>
>>A column named 'Answer' already belongs to this
>>DataTable: cannot set a nested table name to the same
>>name.
>>Description: An unhandled exception occurred during the
>>execution of the current web request. Please review the
>>stack trace for more information about the error and
>>where it originated in the code.
>>
>>Exception Details: System.Data.DuplicateNameException:

A
>>column named 'Answer' already belongs to this

DataTable:
>>cannot set a nested table name to the same name.
>>
>>
>>

>
>
>.
>

 
Reply With Quote
 
Scot Rose [MSFT]
Guest
Posts: n/a
 
      14th Jul 2003
Check the XML and find out if there is in fact a Column name with the same name as a nested table, If there is, modify one or the other and see if the error still occurs...

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (E-Mail Removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
>Content-Class: urn:content-classes:message
>From: "Butch" <(E-Mail Removed)>
>Sender: "Butch" <(E-Mail Removed)>
>References: <008e01c3462f$277dd0f0$(E-Mail Removed)> <#(E-Mail Removed)>
>Subject: RE: Differnt behavior of ADO.Net Relation.Nested under 1.1
>Date: Thu, 10 Jul 2003 07:35:58 -0700
>Lines: 187
>Message-ID: <0cbb01c346f0$93bb3200$(E-Mail Removed)>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Thread-Index: AcNG8JO7Ol/whvtUR/2BYKHzDzxPnQ==
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>Newsgroups: microsoft.public.dotnet.framework.adonet
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:55344
>NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
>X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
>
>OK, something in xml then. I am stuck. Why did code
>execute as expected under vs net 2002 with framework 1.0.
>and now not behave correctly ? The only change here is
>new framework.
>I'd like to make the sample work. Much of the
>functionality is usefull to me. I have seen some others
>with this problem on other news groups.
>Do you know if authors of msdn article are aware that
>code is broken ?
>The code is broken ? You reproduced error ?
>Anyway thanks for help so far.
>
>>-----Original Message-----
>>There may be something wrong with the XML, The error

>message is pretty specific that a tnested table is trying
>to be named the same as a column name and that this
>cannot be
>>done... The following code does not reproduce any errors

>and outputs a properly nested XML output...
>>
>> Dim nwindConn As

>System.Data.SqlClient.SqlConnection = New
>System.Data.SqlClient.SqlConnection("Data
>Source=MyServer;uid=sa;pwd=Password;Initial
>>Catalog=Northwind;")
>> Dim custDA As

>System.Data.SqlClient.SqlDataAdapter = New
>System.Data.SqlClient.SqlDataAdapter("SELECT CustomerID,
>CompanyName FROM Customers",
>>nwindConn)
>> Dim orderDA As

>System.Data.SqlClient.SqlDataAdapter = New
>System.Data.SqlClient.SqlDataAdapter("SELECT OrderID,
>CustomerID, OrderDate FROM Orders",
>>nwindConn)
>>
>> nwindConn.Open()
>>
>> Dim custDS As DataSet = New DataSet

>("CustomerOrders")
>> custDA.Fill(custDS, "Customers")
>> orderDA.Fill(custDS, "Orders")
>>
>> nwindConn.Close()
>>
>> Dim custOrderRel As DataRelation =

>custDS.Relations.Add("CustOrders", custDS.Tables
>("Customers").Columns("CustomerID"), custDS.Tables
>("Orders").Columns
>>("CustomerID"))
>> custOrderRel.Nested = True
>> custDS.WriteXml("D:\MyTest.xml")
>>
>>so it appears that Relation.Nested is working properly

>in 1.1...
>>
>>Want to know more? Check out the MSDN Library at

>http://msdn.microsoft.com or the Microsoft Knowledge
>Base at http://support.microsoft.com
>>
>>Scot Rose, MCSD
>>Microsoft Visual Basic Developer Support
>>Email : (E-Mail Removed) <Remove word online.

>from address>
>>
>>This posting is provided "AS IS", with no warranties,

>and confers no rights.
>>
>>
>>
>>
>>--------------------
>>>Content-Class: urn:content-classes:message
>>>From: "Butch" <(E-Mail Removed)>
>>>Sender: "Butch" <(E-Mail Removed)>
>>>Subject: Differnt behavior of ADO.Net Relation.Nested

>under 1.1
>>>Date: Wed, 9 Jul 2003 08:31:23 -0700
>>>Lines: 82
>>>Message-ID: <008e01c3462f$277dd0f0$(E-Mail Removed)>
>>>MIME-Version: 1.0
>>>Content-Type: text/plain;
>>> charset="iso-8859-1"
>>>Content-Transfer-Encoding: 7bit
>>>X-Newsreader: Microsoft CDO for Windows 2000
>>>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>>>Thread-Index: AcNGLyd9Sk9FnLumQI22EJeCaBbujg==
>>>Newsgroups: microsoft.public.dotnet.framework.adonet
>>>NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
>>>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!

>cpmsftngxa09.phx.gbl
>>>Xref: cpmsftngxa06.phx.gbl

>microsoft.public.dotnet.framework.adonet:55253
>>>X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
>>>
>>>I have an example from MSDN that seems to have worked
>>>under 1.0. It does not under 1.1.
>>>This is the survey example found at:
>>>
>>>http://msdn.microsoft.com/library/default.asp?
>>>url=/library/en-us/dnaspp/html/surveysample2.asp
>>>
>>>The write up found there explains how and why the

>author
>>>must change from code some of the properties of her
>>>strongly typed dataset. Her code apparently runs fine

>on
>>>1.0 but will error at rel.Nested = true when using Net
>>>Framework V1.1.
>>>
>>>Here is her code:
>>>
>>>Public Class ResponseDataSet
>>> Inherits BaseResponseDataSet
>>>
>>> Public Sub New()
>>> MyBase.New()
>>> AdjustQuestionPrimaryKey()
>>> End Sub
>>>
>>> Protected Sub New(ByVal info As SerializationInfo,_
>>> ByVal context As StreamingContext)
>>> MyBase.New(info, context)
>>> AdjustQuestionPrimaryKey()
>>> End Sub
>>>
>>> ' This method sets the primary key for the Question
>>>table
>>> ' to the Id column drawn from the original data
>>> ' rather than the Id column created by the
>>>autogenerated code
>>> Public Sub AdjustQuestionPrimaryKey()
>>>
>>> Answer.Constraints.Remove("Question_Answer")
>>> Question.Constraints.Clear()
>>>
>>> Question.PrimaryKey = New DataColumn()
>>>{Question.Columns("Id")}
>>>
>>> Dim fkc As ForeignKeyConstraint
>>> fkc = New ForeignKeyConstraint

>("Question_Answer",_
>>> New DataColumn() {Question.Columns
>>>("Id")},_
>>> New DataColumn(){Answer.Columns
>>>("Question_Id")})
>>> fkc.AcceptRejectRule = AcceptRejectRule.None
>>> fkc.DeleteRule = Rule.Cascade
>>> fkc.UpdateRule = Rule.Cascade
>>> Answer.Constraints.Add(fkc)
>>>
>>> Relations.Remove("Question_Answer")
>>> Dim rel As DataRelation = New DataRelation
>>>("Question_Answer",_
>>> New DataColumn() {Question.Columns
>>>("Id")},_
>>> New DataColumn() {Answer.Columns
>>>("Question_Id")},_
>>> False)
>>> rel.Nested = True
>>> Relations.Add(rel)
>>> End Sub
>>>End Class
>>>
>>>Here is the error thrown when hitting the rel.Nested =
>>>True line:
>>>
>>>A column named 'Answer' already belongs to this
>>>DataTable: cannot set a nested table name to the same
>>>name.
>>>Description: An unhandled exception occurred during the
>>>execution of the current web request. Please review the
>>>stack trace for more information about the error and
>>>where it originated in the code.
>>>
>>>Exception Details: System.Data.DuplicateNameException:

>A
>>>column named 'Answer' already belongs to this

>DataTable:
>>>cannot set a nested table name to the same name.
>>>
>>>
>>>

>>
>>
>>.
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: strange Vista behavior that just started---screen blackouts with no relation to UAC Mike Windows Vista Performance 6 11th Oct 2008 08:29 PM
How to change or indciate the type of relation in Relation Diagram =?Utf-8?B?QWxwaGE=?= Microsoft Access Database Table Design 10 16th Aug 2006 10:10 AM
relation 1:m in two datagrid, don't nested Vlada Milicevic Microsoft ADO .NET 1 4th Aug 2005 02:45 PM
Cannot add a nested relation or an element column to a table containing a SimpleContent column. Random Microsoft ASP .NET 1 19th Nov 2004 11:36 PM
Creating Differnt Folders for Differnt Accounts Alton. Microsoft Outlook 1 30th Jul 2003 04:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:09 PM.