B
Butch
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.
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.