| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Cor Ligthert
Guest
Posts: n/a
|
Mauricio,
Did you try already the build in dataset.xmlwrite and dataset.xmlread for the serialization. (There are more overloaded methods to add by instance the schema and even the currentstates when there are still updates to do). I hope this helps? Cor |
|
||
|
||||
|
=?Utf-8?B?TWF1cmljaW8gUGlyZXM=?=
Guest
Posts: n/a
|
Hi Cor,
No, this doesn't help because this serialization is used implicit when we call a remote application method. "Cor Ligthert" wrote: > Mauricio, > > Did you try already the build in dataset.xmlwrite and dataset.xmlread for > the serialization. > > (There are more overloaded methods to add by instance the schema and even > the currentstates when there are still updates to do). > > I hope this helps? > > Cor > > > |
|
||
|
||||
|
Cor Ligthert
Guest
Posts: n/a
|
Mauricio,
Strange, In my opinion can you use this in anyway \\\ Public Class Whatever Public Shared Sub Main() Dim ds As New DataSet Dim dt As New DataTable ds.Tables.Add(dt) dt.Columns.Add() dt.Rows.Add(dt.NewRow) dt.Rows(0).Item(0) = "Hello" Dim sw As New System.IO.StringWriter ds.WriteXml(sw, XmlWriteMode.WriteSchema) Dim mystring As String = sw.ToString Dim sr As New System.IO.StringReader(mystring) Dim ds2 As New DataSet ds2.ReadXml(sr, XmlReadMode.ReadSchema) MessageBox.Show(ds.Tables(0).Rows(0)(0).ToString) End Sub /// What has your code more? Cor |
|
||
|
||||
|
=?Utf-8?B?TWF1cmljaW8gUGlyZXM=?=
Guest
Posts: n/a
|
Hi Cor,
I created my example to show the problem. Actually I have 2 applications (client and server) and when a call a server's method passing along the dataset, the child row vanishes in the server's method. I call the server's method by remoting so the serialization happens. This is the problem. Thanks. Mauricio. "Cor Ligthert" wrote: > Mauricio, > > Strange, > > In my opinion can you use this in anyway > \\\ > Public Class Whatever > Public Shared Sub Main() > Dim ds As New DataSet > Dim dt As New DataTable > ds.Tables.Add(dt) > dt.Columns.Add() > dt.Rows.Add(dt.NewRow) > dt.Rows(0).Item(0) = "Hello" > Dim sw As New System.IO.StringWriter > ds.WriteXml(sw, XmlWriteMode.WriteSchema) > Dim mystring As String = sw.ToString > Dim sr As New System.IO.StringReader(mystring) > Dim ds2 As New DataSet > ds2.ReadXml(sr, XmlReadMode.ReadSchema) > MessageBox.Show(ds.Tables(0).Rows(0)(0).ToString) > End Sub > /// > What has your code more? > > Cor > > > |
|
||
|
||||
|
Patrice
Guest
Posts: n/a
|
Could it be that there is no way to know if the child belongs to the
original deleted row or to the newly created row. What if you have a unique key in the dataset. Does it work then ? Patrice -- "Mauricio Pires" <(E-Mail Removed)> a écrit dans le message de news:04032AF8-353A-4D6A-8D9F-(E-Mail Removed)... > (Above there is the whole code.) > I have a dataset with 2 tables (father and child table) and a > relation between them with cascade for update and delete. > On this DataSet I delete a existing father's row and afterwards create the > same father's row with the same field values and also create a child row. > Afterwards, I execute the serialization of this DataSet to a file and, and > the deserialization to another DataSet. You will see that the deserialized > DataSet doesn't has the chid row (it was vanished). > But note that the child row has vanished only if you create the father's > row with the same field's value from the deleted father's row. > This is a terrible problem. How can we use this technology in a serious > application? > Can someone help me? > > *** The code *** > It is necessary to create a Form (Form1), copy the variable declarations and > copy the statements inside the Form1_Load(). > Thanks. > Mauricio Pires > ControlBase (Brazil) > > 'Variable declarations" > Friend FatherTable As New DataTable("FatherTable") > Friend ChildTable As New DataTable("ChildTable") > > Friend dsOriginal As New DataSet > Friend dsRead As DataSet > Friend WithEvents DataGridOriginalFather As System.Windows.Forms.DataGrid > Friend WithEvents DataGridOriginalChild As System.Windows.Forms.DataGrid > > 'Form_Load > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > Me.ClientSize = New System.Drawing.Size(600, 266) > > 'Creating the DataGrids > Me.DataGridOriginalFather = New System.Windows.Forms.DataGrid > Me.DataGridOriginalFather.CaptionText = "Original Father" > Me.DataGridOriginalFather.Location = New System.Drawing.Point(56, 24) > Me.DataGridOriginalFather.Name = "DataGridOriginalFather" > Me.DataGridOriginalFather.Size = New System.Drawing.Size(184, 112) > > Me.DataGridOriginalChild = New System.Windows.Forms.DataGrid > Me.DataGridOriginalChild.CaptionText = "Original Child" > Me.DataGridOriginalChild.Location = New System.Drawing.Point(40, 168) > Me.DataGridOriginalChild.Name = "DataGridOriginalChild" > Me.DataGridOriginalChild.Size = New System.Drawing.Size(232, 80) > > Me.DataGridDeserializedFather = New System.Windows.Forms.DataGrid > Me.DataGridDeserializedFather.CaptionText = "Deserialized Father" > Me.DataGridDeserializedFather.Location = New > System.Drawing.Point(344, 24) > Me.DataGridDeserializedFather.Name = "DataGridDeserializedFather" > Me.DataGridDeserializedFather.Size = New System.Drawing.Size(184, 120) > > Me.DataGridDeserializedChild = New System.Windows.Forms.DataGrid > Me.DataGridDeserializedChild.CaptionText = "Deserialized Child (the > child vanished)" > Me.DataGridDeserializedChild.HeaderForeColor = > System.Drawing.SystemColors.ControlText > Me.DataGridDeserializedChild.Location = New > System.Drawing.Point(328, 168) > Me.DataGridDeserializedChild.Name = "DataGridDeserializedChild" > Me.DataGridDeserializedChild.Size = New System.Drawing.Size(232, 80) > > Me.Controls.Add(Me.DataGridOriginalChild) > Me.Controls.Add(Me.DataGridOriginalFather) > Me.Controls.Add(Me.DataGridDeserializedFather) > Me.Controls.Add(Me.DataGridDeserializedChild) > > 'Creating 2 tables (father and child tables) and a relation > Dim fatherCol1 As New DataColumn("FatherCol1") > Dim childCol1 As New DataColumn("ChildCol1") > Dim childCol2 As New DataColumn("ChildCol2") > > FatherTable.Columns.Add(fatherCol1) > ChildTable.Columns.Add(childCol1) > ChildTable.Columns.Add(childCol2) > > dsOriginal.Tables.Add(FatherTable) > dsOriginal.Tables.Add(ChildTable) > dsOriginal.Relations.Add("FatherChildRelation", fatherCol1, childCol1) > > 'Creating a father row > FatherTable.Rows.Add(New Object() {"Father1"}) > Me.dsOriginal.AcceptChanges() > > 'Deleting the father row that was created above > FatherTable.Rows(0).Delete() > > 'Creating the same father row again > FatherTable.Rows.Add(New Object() {"Father1"}) > > 'Creating a child row > ChildTable.Rows.Add(New Object() {"Father1", "Child1"}) > > 'Serialization to "myFile.xml" > Dim mySerializer As New > System.Xml.Serialization.XmlSerializer(GetType(DataSet)) > Dim myWriter As IO.StreamWriter = New > IO.StreamWriter("myFileName.xml") > mySerializer.Serialize(myWriter, dsOriginal) > myWriter.Close() > > 'Deserialization (see that dataset lost the child row) > Dim myFileStream As IO.FileStream = New > IO.FileStream("myFileName.xml", IO.FileMode.Open) > ' Calls the Deserialize. > dsRead = CType( _ > mySerializer.Deserialize(myFileStream), DataSet) > myFileStream.Close() > > 'This DataDrid show the DataSet with one father and one child rows > (OK) > Me.DataGridOriginalFather.SetDataBinding(dsOriginal, "FatherTable") > Me.DataGridOriginalChild.SetDataBinding(dsOriginal, > "FatherTable.FatherChildRelation") > > 'These DataGrids show the dataset with one father and anyone chid > row (The child vanished) > Me.DataGridDeserializedFather.SetDataBinding(Me.dsRead, "FatherTable") > Me.DataGridDeserializedChild.SetDataBinding(Me.dsRead, > "FatherTable.FatherChildRelation") > End Sub > > '------ THE END ------------- |
|
||
|
||||
|
=?Utf-8?B?TWF1cmljaW8gUGlyZXM=?=
Guest
Posts: n/a
|
Even with unique key in dataset it doesn't work.
Did you notice that the child only vanishes if the father row has the same deleted father value. If you input a father row with other values, it's ok. Mauricio Thanks. "Patrice" wrote: > Could it be that there is no way to know if the child belongs to the > original deleted row or to the newly created row. > > What if you have a unique key in the dataset. Does it work then ? > > Patrice > > -- > > "Mauricio Pires" <(E-Mail Removed)> a écrit dans le > message de news:04032AF8-353A-4D6A-8D9F-(E-Mail Removed)... > > (Above there is the whole code.) > > I have a dataset with 2 tables (father and child table) and a > > relation between them with cascade for update and delete. > > On this DataSet I delete a existing father's row and afterwards create the > > same father's row with the same field values and also create a child row. > > Afterwards, I execute the serialization of this DataSet to a file and, and > > the deserialization to another DataSet. You will see that the deserialized > > DataSet doesn't has the chid row (it was vanished). > > But note that the child row has vanished only if you create the father's > > row with the same field's value from the deleted father's row. > > This is a terrible problem. How can we use this technology in a serious > > application? > > Can someone help me? > > > > *** The code *** > > It is necessary to create a Form (Form1), copy the variable declarations > and > > copy the statements inside the Form1_Load(). > > Thanks. > > Mauricio Pires > > ControlBase (Brazil) > > > > 'Variable declarations" > > Friend FatherTable As New DataTable("FatherTable") > > Friend ChildTable As New DataTable("ChildTable") > > > > Friend dsOriginal As New DataSet > > Friend dsRead As DataSet > > Friend WithEvents DataGridOriginalFather As System.Windows.Forms.DataGrid > > Friend WithEvents DataGridOriginalChild As System.Windows.Forms.DataGrid > > > > 'Form_Load > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > > > Me.ClientSize = New System.Drawing.Size(600, 266) > > > > 'Creating the DataGrids > > Me.DataGridOriginalFather = New System.Windows.Forms.DataGrid > > Me.DataGridOriginalFather.CaptionText = "Original Father" > > Me.DataGridOriginalFather.Location = New System.Drawing.Point(56, > 24) > > Me.DataGridOriginalFather.Name = "DataGridOriginalFather" > > Me.DataGridOriginalFather.Size = New System.Drawing.Size(184, 112) > > > > Me.DataGridOriginalChild = New System.Windows.Forms.DataGrid > > Me.DataGridOriginalChild.CaptionText = "Original Child" > > Me.DataGridOriginalChild.Location = New System.Drawing.Point(40, > 168) > > Me.DataGridOriginalChild.Name = "DataGridOriginalChild" > > Me.DataGridOriginalChild.Size = New System.Drawing.Size(232, 80) > > > > Me.DataGridDeserializedFather = New System.Windows.Forms.DataGrid > > Me.DataGridDeserializedFather.CaptionText = "Deserialized Father" > > Me.DataGridDeserializedFather.Location = New > > System.Drawing.Point(344, 24) > > Me.DataGridDeserializedFather.Name = "DataGridDeserializedFather" > > Me.DataGridDeserializedFather.Size = New System.Drawing.Size(184, > 120) > > > > Me.DataGridDeserializedChild = New System.Windows.Forms.DataGrid > > Me.DataGridDeserializedChild.CaptionText = "Deserialized Child > (the > > child vanished)" > > Me.DataGridDeserializedChild.HeaderForeColor = > > System.Drawing.SystemColors.ControlText > > Me.DataGridDeserializedChild.Location = New > > System.Drawing.Point(328, 168) > > Me.DataGridDeserializedChild.Name = "DataGridDeserializedChild" > > Me.DataGridDeserializedChild.Size = New System.Drawing.Size(232, > 80) > > > > Me.Controls.Add(Me.DataGridOriginalChild) > > Me.Controls.Add(Me.DataGridOriginalFather) > > Me.Controls.Add(Me.DataGridDeserializedFather) > > Me.Controls.Add(Me.DataGridDeserializedChild) > > > > 'Creating 2 tables (father and child tables) and a relation > > Dim fatherCol1 As New DataColumn("FatherCol1") > > Dim childCol1 As New DataColumn("ChildCol1") > > Dim childCol2 As New DataColumn("ChildCol2") > > > > FatherTable.Columns.Add(fatherCol1) > > ChildTable.Columns.Add(childCol1) > > ChildTable.Columns.Add(childCol2) > > > > dsOriginal.Tables.Add(FatherTable) > > dsOriginal.Tables.Add(ChildTable) > > dsOriginal.Relations.Add("FatherChildRelation", fatherCol1, > childCol1) > > > > 'Creating a father row > > FatherTable.Rows.Add(New Object() {"Father1"}) > > Me.dsOriginal.AcceptChanges() > > > > 'Deleting the father row that was created above > > FatherTable.Rows(0).Delete() > > > > 'Creating the same father row again > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > > 'Creating a child row > > ChildTable.Rows.Add(New Object() {"Father1", "Child1"}) > > > > 'Serialization to "myFile.xml" > > Dim mySerializer As New > > System.Xml.Serialization.XmlSerializer(GetType(DataSet)) > > Dim myWriter As IO.StreamWriter = New > > IO.StreamWriter("myFileName.xml") > > mySerializer.Serialize(myWriter, dsOriginal) > > myWriter.Close() > > > > 'Deserialization (see that dataset lost the child row) > > Dim myFileStream As IO.FileStream = New > > IO.FileStream("myFileName.xml", IO.FileMode.Open) > > ' Calls the Deserialize. > > dsRead = CType( _ > > mySerializer.Deserialize(myFileStream), DataSet) > > myFileStream.Close() > > > > 'This DataDrid show the DataSet with one father and one child rows > > (OK) > > Me.DataGridOriginalFather.SetDataBinding(dsOriginal, > "FatherTable") > > Me.DataGridOriginalChild.SetDataBinding(dsOriginal, > > "FatherTable.FatherChildRelation") > > > > 'These DataGrids show the dataset with one father and anyone chid > > row (The child vanished) > > Me.DataGridDeserializedFather.SetDataBinding(Me.dsRead, > "FatherTable") > > Me.DataGridDeserializedChild.SetDataBinding(Me.dsRead, > > "FatherTable.FatherChildRelation") > > End Sub > > > > '------ THE END ------------- > > > |
|
||
|
||||
|
=?Utf-8?B?TWF1cmljaW8gUGlyZXM=?=
Guest
Posts: n/a
|
No, the problem happens even with a unique key.
Notice that the problem only happens if the new father row has the same values from the deleted father row. if the new father row has different field values, it's ok. Thanks. Mauricio. "Patrice" wrote: > Could it be that there is no way to know if the child belongs to the > original deleted row or to the newly created row. > > What if you have a unique key in the dataset. Does it work then ? > > Patrice > > -- > > "Mauricio Pires" <(E-Mail Removed)> a écrit dans le > message de news:04032AF8-353A-4D6A-8D9F-(E-Mail Removed)... > > (Above there is the whole code.) > > I have a dataset with 2 tables (father and child table) and a > > relation between them with cascade for update and delete. > > On this DataSet I delete a existing father's row and afterwards create the > > same father's row with the same field values and also create a child row. > > Afterwards, I execute the serialization of this DataSet to a file and, and > > the deserialization to another DataSet. You will see that the deserialized > > DataSet doesn't has the chid row (it was vanished). > > But note that the child row has vanished only if you create the father's > > row with the same field's value from the deleted father's row. > > This is a terrible problem. How can we use this technology in a serious > > application? > > Can someone help me? > > > > *** The code *** > > It is necessary to create a Form (Form1), copy the variable declarations > and > > copy the statements inside the Form1_Load(). > > Thanks. > > Mauricio Pires > > ControlBase (Brazil) > > > > 'Variable declarations" > > Friend FatherTable As New DataTable("FatherTable") > > Friend ChildTable As New DataTable("ChildTable") > > > > Friend dsOriginal As New DataSet > > Friend dsRead As DataSet > > Friend WithEvents DataGridOriginalFather As System.Windows.Forms.DataGrid > > Friend WithEvents DataGridOriginalChild As System.Windows.Forms.DataGrid > > > > 'Form_Load > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > > > Me.ClientSize = New System.Drawing.Size(600, 266) > > > > 'Creating the DataGrids > > Me.DataGridOriginalFather = New System.Windows.Forms.DataGrid > > Me.DataGridOriginalFather.CaptionText = "Original Father" > > Me.DataGridOriginalFather.Location = New System.Drawing.Point(56, > 24) > > Me.DataGridOriginalFather.Name = "DataGridOriginalFather" > > Me.DataGridOriginalFather.Size = New System.Drawing.Size(184, 112) > > > > Me.DataGridOriginalChild = New System.Windows.Forms.DataGrid > > Me.DataGridOriginalChild.CaptionText = "Original Child" > > Me.DataGridOriginalChild.Location = New System.Drawing.Point(40, > 168) > > Me.DataGridOriginalChild.Name = "DataGridOriginalChild" > > Me.DataGridOriginalChild.Size = New System.Drawing.Size(232, 80) > > > > Me.DataGridDeserializedFather = New System.Windows.Forms.DataGrid > > Me.DataGridDeserializedFather.CaptionText = "Deserialized Father" > > Me.DataGridDeserializedFather.Location = New > > System.Drawing.Point(344, 24) > > Me.DataGridDeserializedFather.Name = "DataGridDeserializedFather" > > Me.DataGridDeserializedFather.Size = New System.Drawing.Size(184, > 120) > > > > Me.DataGridDeserializedChild = New System.Windows.Forms.DataGrid > > Me.DataGridDeserializedChild.CaptionText = "Deserialized Child > (the > > child vanished)" > > Me.DataGridDeserializedChild.HeaderForeColor = > > System.Drawing.SystemColors.ControlText > > Me.DataGridDeserializedChild.Location = New > > System.Drawing.Point(328, 168) > > Me.DataGridDeserializedChild.Name = "DataGridDeserializedChild" > > Me.DataGridDeserializedChild.Size = New System.Drawing.Size(232, > 80) > > > > Me.Controls.Add(Me.DataGridOriginalChild) > > Me.Controls.Add(Me.DataGridOriginalFather) > > Me.Controls.Add(Me.DataGridDeserializedFather) > > Me.Controls.Add(Me.DataGridDeserializedChild) > > > > 'Creating 2 tables (father and child tables) and a relation > > Dim fatherCol1 As New DataColumn("FatherCol1") > > Dim childCol1 As New DataColumn("ChildCol1") > > Dim childCol2 As New DataColumn("ChildCol2") > > > > FatherTable.Columns.Add(fatherCol1) > > ChildTable.Columns.Add(childCol1) > > ChildTable.Columns.Add(childCol2) > > > > dsOriginal.Tables.Add(FatherTable) > > dsOriginal.Tables.Add(ChildTable) > > dsOriginal.Relations.Add("FatherChildRelation", fatherCol1, > childCol1) > > > > 'Creating a father row > > FatherTable.Rows.Add(New Object() {"Father1"}) > > Me.dsOriginal.AcceptChanges() > > > > 'Deleting the father row that was created above > > FatherTable.Rows(0).Delete() > > > > 'Creating the same father row again > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > > 'Creating a child row > > ChildTable.Rows.Add(New Object() {"Father1", "Child1"}) > > > > 'Serialization to "myFile.xml" > > Dim mySerializer As New > > System.Xml.Serialization.XmlSerializer(GetType(DataSet)) > > Dim myWriter As IO.StreamWriter = New > > IO.StreamWriter("myFileName.xml") > > mySerializer.Serialize(myWriter, dsOriginal) > > myWriter.Close() > > > > 'Deserialization (see that dataset lost the child row) > > Dim myFileStream As IO.FileStream = New > > IO.FileStream("myFileName.xml", IO.FileMode.Open) > > ' Calls the Deserialize. > > dsRead = CType( _ > > mySerializer.Deserialize(myFileStream), DataSet) > > myFileStream.Close() > > > > 'This DataDrid show the DataSet with one father and one child rows > > (OK) > > Me.DataGridOriginalFather.SetDataBinding(dsOriginal, > "FatherTable") > > Me.DataGridOriginalChild.SetDataBinding(dsOriginal, > > "FatherTable.FatherChildRelation") > > > > 'These DataGrids show the dataset with one father and anyone chid > > row (The child vanished) > > Me.DataGridDeserializedFather.SetDataBinding(Me.dsRead, > "FatherTable") > > Me.DataGridDeserializedChild.SetDataBinding(Me.dsRead, > > "FatherTable.FatherChildRelation") > > End Sub > > > > '------ THE END ------------- > > > |
|
||
|
||||
|
Patrice
Guest
Posts: n/a
|
This is precisely (that it works if the value is different but fails if this
is the same) what makes me think that you wouldn't have this problem with a "true" pk. You'll have to establish the relation on this new pk field. I 'm assuming also that you never reuse an already used value for this pk field (basically autoincrement or guid) as this is done usually for PKs... Also what if you call AcceptChanges just before serializing ? It would remove the deleted row and could perhaps solve the problem ? Patrice -- "Mauricio Pires" <(E-Mail Removed)> a écrit dans le message de news:E99FF8CE-D634-4D1D-A3E7-(E-Mail Removed)... > Even with unique key in dataset it doesn't work. > Did you notice that the child only vanishes if the father row has the same > deleted father value. If you input a father row with other values, it's ok. > Mauricio > Thanks. > > "Patrice" wrote: > > > Could it be that there is no way to know if the child belongs to the > > original deleted row or to the newly created row. > > > > What if you have a unique key in the dataset. Does it work then ? > > > > Patrice > > > > -- > > > > "Mauricio Pires" <(E-Mail Removed)> a écrit dans le > > message de news:04032AF8-353A-4D6A-8D9F-(E-Mail Removed)... > > > (Above there is the whole code.) > > > I have a dataset with 2 tables (father and child table) and a > > > relation between them with cascade for update and delete. > > > On this DataSet I delete a existing father's row and afterwards create the > > > same father's row with the same field values and also create a child row. > > > Afterwards, I execute the serialization of this DataSet to a file and, and > > > the deserialization to another DataSet. You will see that the deserialized > > > DataSet doesn't has the chid row (it was vanished). > > > But note that the child row has vanished only if you create the father's > > > row with the same field's value from the deleted father's row. > > > This is a terrible problem. How can we use this technology in a serious > > > application? > > > Can someone help me? > > > > > > *** The code *** > > > It is necessary to create a Form (Form1), copy the variable declarations > > and > > > copy the statements inside the Form1_Load(). > > > Thanks. > > > Mauricio Pires > > > ControlBase (Brazil) > > > > > > 'Variable declarations" > > > Friend FatherTable As New DataTable("FatherTable") > > > Friend ChildTable As New DataTable("ChildTable") > > > > > > Friend dsOriginal As New DataSet > > > Friend dsRead As DataSet > > > Friend WithEvents DataGridOriginalFather As System.Windows.Forms.DataGrid > > > Friend WithEvents DataGridOriginalChild As System.Windows.Forms.DataGrid > > > > > > 'Form_Load > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles MyBase.Load > > > > > > Me.ClientSize = New System.Drawing.Size(600, 266) > > > > > > 'Creating the DataGrids > > > Me.DataGridOriginalFather = New System.Windows.Forms.DataGrid > > > Me.DataGridOriginalFather.CaptionText = "Original Father" > > > Me.DataGridOriginalFather.Location = New System.Drawing.Point(56, > > 24) > > > Me.DataGridOriginalFather.Name = "DataGridOriginalFather" > > > Me.DataGridOriginalFather.Size = New System.Drawing.Size(184, 112) > > > > > > Me.DataGridOriginalChild = New System.Windows.Forms.DataGrid > > > Me.DataGridOriginalChild.CaptionText = "Original Child" > > > Me.DataGridOriginalChild.Location = New System.Drawing.Point(40, > > 168) > > > Me.DataGridOriginalChild.Name = "DataGridOriginalChild" > > > Me.DataGridOriginalChild.Size = New System.Drawing.Size(232, 80) > > > > > > Me.DataGridDeserializedFather = New System.Windows.Forms.DataGrid > > > Me.DataGridDeserializedFather.CaptionText = "Deserialized Father" > > > Me.DataGridDeserializedFather.Location = New > > > System.Drawing.Point(344, 24) > > > Me.DataGridDeserializedFather.Name = "DataGridDeserializedFather" > > > Me.DataGridDeserializedFather.Size = New System.Drawing.Size(184, > > 120) > > > > > > Me.DataGridDeserializedChild = New System.Windows.Forms.DataGrid > > > Me.DataGridDeserializedChild.CaptionText = "Deserialized Child > > (the > > > child vanished)" > > > Me.DataGridDeserializedChild.HeaderForeColor = > > > System.Drawing.SystemColors.ControlText > > > Me.DataGridDeserializedChild.Location = New > > > System.Drawing.Point(328, 168) > > > Me.DataGridDeserializedChild.Name = "DataGridDeserializedChild" > > > Me.DataGridDeserializedChild.Size = New System.Drawing.Size(232, > > 80) > > > > > > Me.Controls.Add(Me.DataGridOriginalChild) > > > Me.Controls.Add(Me.DataGridOriginalFather) > > > Me.Controls.Add(Me.DataGridDeserializedFather) > > > Me.Controls.Add(Me.DataGridDeserializedChild) > > > > > > 'Creating 2 tables (father and child tables) and a relation > > > Dim fatherCol1 As New DataColumn("FatherCol1") > > > Dim childCol1 As New DataColumn("ChildCol1") > > > Dim childCol2 As New DataColumn("ChildCol2") > > > > > > FatherTable.Columns.Add(fatherCol1) > > > ChildTable.Columns.Add(childCol1) > > > ChildTable.Columns.Add(childCol2) > > > > > > dsOriginal.Tables.Add(FatherTable) > > > dsOriginal.Tables.Add(ChildTable) > > > dsOriginal.Relations.Add("FatherChildRelation", fatherCol1, > > childCol1) > > > > > > 'Creating a father row > > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > Me.dsOriginal.AcceptChanges() > > > > > > 'Deleting the father row that was created above > > > FatherTable.Rows(0).Delete() > > > > > > 'Creating the same father row again > > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > > > > 'Creating a child row > > > ChildTable.Rows.Add(New Object() {"Father1", "Child1"}) > > > > > > 'Serialization to "myFile.xml" > > > Dim mySerializer As New > > > System.Xml.Serialization.XmlSerializer(GetType(DataSet)) > > > Dim myWriter As IO.StreamWriter = New > > > IO.StreamWriter("myFileName.xml") > > > mySerializer.Serialize(myWriter, dsOriginal) > > > myWriter.Close() > > > > > > 'Deserialization (see that dataset lost the child row) > > > Dim myFileStream As IO.FileStream = New > > > IO.FileStream("myFileName.xml", IO.FileMode.Open) > > > ' Calls the Deserialize. > > > dsRead = CType( _ > > > mySerializer.Deserialize(myFileStream), DataSet) > > > myFileStream.Close() > > > > > > 'This DataDrid show the DataSet with one father and one child rows > > > (OK) > > > Me.DataGridOriginalFather.SetDataBinding(dsOriginal, > > "FatherTable") > > > Me.DataGridOriginalChild.SetDataBinding(dsOriginal, > > > "FatherTable.FatherChildRelation") > > > > > > 'These DataGrids show the dataset with one father and anyone chid > > > row (The child vanished) > > > Me.DataGridDeserializedFather.SetDataBinding(Me.dsRead, > > "FatherTable") > > > Me.DataGridDeserializedChild.SetDataBinding(Me.dsRead, > > > "FatherTable.FatherChildRelation") > > > End Sub > > > > > > '------ THE END ------------- > > > > > > |
|
||
|
||||
|
=?Utf-8?B?TWF1cmljaW8gUGlyZXM=?=
Guest
Posts: n/a
|
No, I can't call AcceptChanges() because I will lose the modified, deleted
and inserted rows which are passed to my server application. "Patrice" wrote: > This is precisely (that it works if the value is different but fails if this > is the same) what makes me think that you wouldn't have this problem with a > "true" pk. > You'll have to establish the relation on this new pk field. I 'm assuming > also that you never reuse an already used value for this pk field (basically > autoincrement or guid) as this is done usually for PKs... > > Also what if you call AcceptChanges just before serializing ? It would > remove the deleted row and could perhaps solve the problem ? > > Patrice > > > -- > > "Mauricio Pires" <(E-Mail Removed)> a écrit dans le > message de news:E99FF8CE-D634-4D1D-A3E7-(E-Mail Removed)... > > Even with unique key in dataset it doesn't work. > > Did you notice that the child only vanishes if the father row has the same > > deleted father value. If you input a father row with other values, it's > ok. > > Mauricio > > Thanks. > > > > "Patrice" wrote: > > > > > Could it be that there is no way to know if the child belongs to the > > > original deleted row or to the newly created row. > > > > > > What if you have a unique key in the dataset. Does it work then ? > > > > > > Patrice > > > > > > -- > > > > > > "Mauricio Pires" <(E-Mail Removed)> a écrit dans > le > > > message de news:04032AF8-353A-4D6A-8D9F-(E-Mail Removed)... > > > > (Above there is the whole code.) > > > > I have a dataset with 2 tables (father and child table) and a > > > > relation between them with cascade for update and delete. > > > > On this DataSet I delete a existing father's row and afterwards create > the > > > > same father's row with the same field values and also create a child > row. > > > > Afterwards, I execute the serialization of this DataSet to a file and, > and > > > > the deserialization to another DataSet. You will see that the > deserialized > > > > DataSet doesn't has the chid row (it was vanished). > > > > But note that the child row has vanished only if you create the > father's > > > > row with the same field's value from the deleted father's row. > > > > This is a terrible problem. How can we use this technology in a > serious > > > > application? > > > > Can someone help me? > > > > > > > > *** The code *** > > > > It is necessary to create a Form (Form1), copy the variable > declarations > > > and > > > > copy the statements inside the Form1_Load(). > > > > Thanks. > > > > Mauricio Pires > > > > ControlBase (Brazil) > > > > > > > > 'Variable declarations" > > > > Friend FatherTable As New DataTable("FatherTable") > > > > Friend ChildTable As New DataTable("ChildTable") > > > > > > > > Friend dsOriginal As New DataSet > > > > Friend dsRead As DataSet > > > > Friend WithEvents DataGridOriginalFather As > System.Windows.Forms.DataGrid > > > > Friend WithEvents DataGridOriginalChild As > System.Windows.Forms.DataGrid > > > > > > > > 'Form_Load > > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > > System.EventArgs) Handles MyBase.Load > > > > > > > > Me.ClientSize = New System.Drawing.Size(600, 266) > > > > > > > > 'Creating the DataGrids > > > > Me.DataGridOriginalFather = New System.Windows.Forms.DataGrid > > > > Me.DataGridOriginalFather.CaptionText = "Original Father" > > > > Me.DataGridOriginalFather.Location = New > System.Drawing.Point(56, > > > 24) > > > > Me.DataGridOriginalFather.Name = "DataGridOriginalFather" > > > > Me.DataGridOriginalFather.Size = New System.Drawing.Size(184, > 112) > > > > > > > > Me.DataGridOriginalChild = New System.Windows.Forms.DataGrid > > > > Me.DataGridOriginalChild.CaptionText = "Original Child" > > > > Me.DataGridOriginalChild.Location = New > System.Drawing.Point(40, > > > 168) > > > > Me.DataGridOriginalChild.Name = "DataGridOriginalChild" > > > > Me.DataGridOriginalChild.Size = New System.Drawing.Size(232, > 80) > > > > > > > > Me.DataGridDeserializedFather = New > System.Windows.Forms.DataGrid > > > > Me.DataGridDeserializedFather.CaptionText = "Deserialized > Father" > > > > Me.DataGridDeserializedFather.Location = New > > > > System.Drawing.Point(344, 24) > > > > Me.DataGridDeserializedFather.Name = > "DataGridDeserializedFather" > > > > Me.DataGridDeserializedFather.Size = New > System.Drawing.Size(184, > > > 120) > > > > > > > > Me.DataGridDeserializedChild = New > System.Windows.Forms.DataGrid > > > > Me.DataGridDeserializedChild.CaptionText = "Deserialized Child > > > (the > > > > child vanished)" > > > > Me.DataGridDeserializedChild.HeaderForeColor = > > > > System.Drawing.SystemColors.ControlText > > > > Me.DataGridDeserializedChild.Location = New > > > > System.Drawing.Point(328, 168) > > > > Me.DataGridDeserializedChild.Name = > "DataGridDeserializedChild" > > > > Me.DataGridDeserializedChild.Size = New > System.Drawing.Size(232, > > > 80) > > > > > > > > Me.Controls.Add(Me.DataGridOriginalChild) > > > > Me.Controls.Add(Me.DataGridOriginalFather) > > > > Me.Controls.Add(Me.DataGridDeserializedFather) > > > > Me.Controls.Add(Me.DataGridDeserializedChild) > > > > > > > > 'Creating 2 tables (father and child tables) and a relation > > > > Dim fatherCol1 As New DataColumn("FatherCol1") > > > > Dim childCol1 As New DataColumn("ChildCol1") > > > > Dim childCol2 As New DataColumn("ChildCol2") > > > > > > > > FatherTable.Columns.Add(fatherCol1) > > > > ChildTable.Columns.Add(childCol1) > > > > ChildTable.Columns.Add(childCol2) > > > > > > > > dsOriginal.Tables.Add(FatherTable) > > > > dsOriginal.Tables.Add(ChildTable) > > > > dsOriginal.Relations.Add("FatherChildRelation", fatherCol1, > > > childCol1) > > > > > > > > 'Creating a father row > > > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > > Me.dsOriginal.AcceptChanges() > > > > > > > > 'Deleting the father row that was created above > > > > FatherTable.Rows(0).Delete() > > > > > > > > 'Creating the same father row again > > > > FatherTable.Rows.Add(New Object() {"Father1"}) > > > > > > > > 'Creating a child row > > > > ChildTable.Rows.Add(New Object() {"Father1", "Child1"}) > > > > > > > > 'Serialization to "myFile.xml" > > > > Dim mySerializer As New > > > > System.Xml.Serialization.XmlSerializer(GetType(DataSet)) > > > > Dim myWriter As IO.StreamWriter = New > > > > IO.StreamWriter("myFileName.xml") > > > > mySerializer.Serialize(myWriter, dsOriginal) > > > > myWriter.Close() > > > > > > > > 'Deserialization (see that dataset lost the child row) > > > > Dim myFileStream As IO.FileStream = New > > > > IO.FileStream("myFileName.xml", IO.FileMode.Open) > > > > ' Calls the Deserialize. > > > > dsRead = CType( _ > > > > mySerializer.Deserialize(myFileStream), DataSet) > > > > myFileStream.Close() > > > > > > > > 'This DataDrid show the DataSet with one father and one child > rows > > > > (OK) > > > > Me.DataGridOriginalFather.SetDataBinding(dsOriginal, > > > "FatherTable") > > > > Me.DataGridOriginalChild.SetDataBinding(dsOriginal, > > > > "FatherTable.FatherChildRelation") > > > > > > > > 'These DataGrids show the dataset with one father and anyone > chid > > > > row (The child vanished) > > > > Me.DataGridDeserializedFather.SetDataBinding(Me.dsRead, > > > "FatherTable") > > > > Me.DataGridDeserializedChild.SetDataBinding(Me.dsRead, > > > > "FatherTable.FatherChildRelation") > > > > End Sub > > > > > > > > '------ THE END ------------- > > > > > > > > > > > > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Possible to tweake dataset (de)serialization .NET 2.0-->1.1? | henk gijsbert | Microsoft ADO .NET | 0 | 11th Jul 2006 08:01 AM |
| Dataset serialization | =?Utf-8?B?QnJpYW4gS2VhdGluZw==?= | Microsoft C# .NET | 4 | 26th Jul 2005 01:25 PM |
| DataSet serialization | Viorel Ghilas | Microsoft ADO .NET | 2 | 6th Feb 2004 01:46 PM |
| DataSet serialization | Viorel Ghilas | Microsoft Dot NET Framework | 0 | 4th Feb 2004 09:04 AM |
| is using a DataSet dangerous? | Francois Malgreve | Microsoft ADO .NET | 7 | 29th Nov 2003 10:43 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




