M
Mustafa Korkmaz
I have a dataset which has the parent child relation set. If I add a
record to the detail table (BTW master table has a record and its row
state is unchanged) and get the changes from the dataset via
getchanges method, I get the detail record (expected) and master table
record (not expected)in the returned dataset. The funny thing I
noticed though, if you check the rowstate of the parent record, it's
still unchanged. What am I missing here?
Here is the xsd file of the dataset
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="dstFormDataType"
targetNamespace="http://tempuri.org/dstFormDataType.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/dstFormDataType.xsd"
xmlns:mstns="http://tempuri.org/dstFormDataType.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="dstFormDataType" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="Field1" type="xs:string" minOccurs="0" />
<xs:element name="Field2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="Field1" type="xs:string" minOccurs="0" />
<xs:element name="Field3" type="xs:string" minOccurs="0" />
<xs:element name="Field4" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="dstFormDataTypeKey1" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Table1" />
<xs:field xpath="mstns:Field1" />
</xs:key>
<xs:key name="dstFormDataTypeKey2" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Table2" />
<xs:field xpath="mstns:Field1" />
<xs:field xpath="mstns:Field3" />
</xs:key>
<xs:keyref name="Table1Table2" refer="dstFormDataTypeKey1"
msdata:AcceptRejectRule="Cascade"
msdataeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Table2" />
<xs:field xpath="mstns:Field1" />
</xs:keyref>
</xs:element>
</xs:schema>
Here is the sample project in vb.net to test.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DstFormData As RowStateTest.dstFormDataType
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DstFormData = New RowStateTest.dstFormDataType
Me.Button1 = New System.Windows.Forms.Button
CType(Me.DstFormData,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DstFormData
'
Me.DstFormData.DataSetName = "dstFormData"
Me.DstFormData.Locale = New
System.Globalization.CultureInfo("en-US")
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(88, 68)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DstFormData,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim drwnew As DataRow = DstFormData.Tables(0).NewRow
drwnew("Field1") = "1"
DstFormData.Tables(0).Rows.Add(drwnew)
DstFormData.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim drwnew As DataRow = DstFormData.Tables(1).NewRow
drwnew("Field1") = "1"
drwnew("Field3") = "2"
DstFormData.Tables(1).Rows.Add(drwnew)
MessageBox.Show(DstFormData.GetChanges.GetXml)
End Sub
End Class
regards,
mk
record to the detail table (BTW master table has a record and its row
state is unchanged) and get the changes from the dataset via
getchanges method, I get the detail record (expected) and master table
record (not expected)in the returned dataset. The funny thing I
noticed though, if you check the rowstate of the parent record, it's
still unchanged. What am I missing here?
Here is the xsd file of the dataset
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="dstFormDataType"
targetNamespace="http://tempuri.org/dstFormDataType.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/dstFormDataType.xsd"
xmlns:mstns="http://tempuri.org/dstFormDataType.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="dstFormDataType" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="Field1" type="xs:string" minOccurs="0" />
<xs:element name="Field2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="Field1" type="xs:string" minOccurs="0" />
<xs:element name="Field3" type="xs:string" minOccurs="0" />
<xs:element name="Field4" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="dstFormDataTypeKey1" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Table1" />
<xs:field xpath="mstns:Field1" />
</xs:key>
<xs:key name="dstFormDataTypeKey2" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Table2" />
<xs:field xpath="mstns:Field1" />
<xs:field xpath="mstns:Field3" />
</xs:key>
<xs:keyref name="Table1Table2" refer="dstFormDataTypeKey1"
msdata:AcceptRejectRule="Cascade"
msdataeleteRule="Cascade" msdata:UpdateRule="Cascade">
<xs:selector xpath=".//mstns:Table2" />
<xs:field xpath="mstns:Field1" />
</xs:keyref>
</xs:element>
</xs:schema>
Here is the sample project in vb.net to test.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DstFormData As RowStateTest.dstFormDataType
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DstFormData = New RowStateTest.dstFormDataType
Me.Button1 = New System.Windows.Forms.Button
CType(Me.DstFormData,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DstFormData
'
Me.DstFormData.DataSetName = "dstFormData"
Me.DstFormData.Locale = New
System.Globalization.CultureInfo("en-US")
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(88, 68)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DstFormData,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim drwnew As DataRow = DstFormData.Tables(0).NewRow
drwnew("Field1") = "1"
DstFormData.Tables(0).Rows.Add(drwnew)
DstFormData.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim drwnew As DataRow = DstFormData.Tables(1).NewRow
drwnew("Field1") = "1"
drwnew("Field3") = "2"
DstFormData.Tables(1).Rows.Add(drwnew)
MessageBox.Show(DstFormData.GetChanges.GetXml)
End Sub
End Class
regards,
mk