G
Guest
Hi ABad,
Excuse I am late. I live in Brazil and here has carnival (4 days). In Rio it
is very famous. Do you like carnival?
Let's go to work.
Imagine a server giving the dataset to a client application. The client
binds this dataset to a datagrid. The client user deletes the father row and,
afterwards, decides to create the same row again. What the client must return
to the server? Isn't the dataset.GetChanges?
I would like to say when a return the dataset.GetChanges to a local method,
it works ok, but if I return to a remote server by remoting, it doesn't work
(the child row vanishes) and I think the serialization doesn't work ok in
this case.
I change your example program again (the code is above) creating a new
column in father table. You will see that the father row was inserted, but
there is no child.
Code:
Sub CreateSchema(ByVal InDS As DataSet)
Dim FatherTable As New DataTable("FatherTable")
Dim ChildTable As New DataTable("ChildTable")
Dim fatherCol1 As New DataColumn("FatherCol1")
'I create a new column in father table
Dim fatherCol2 As New DataColumn("FatherCol2")
Dim childCol1 As New DataColumn("ChildCol1")
Dim childCol2 As New DataColumn("ChildCol2")
FatherTable.Columns.Add(fatherCol1)
FatherTable.Columns.Add(fatherCol2)
ChildTable.Columns.Add(childCol1)
ChildTable.Columns.Add(childCol2)
FatherTable.PrimaryKey = New DataColumn() {fatherCol1}
InDS.Tables.Add(FatherTable)
InDS.Tables.Add(ChildTable)
InDS.Relations.Add("FatherChildRelation", fatherCol1, childCol1)
End Sub
Function CreateOriginalDataset() As DataSet
Dim dsOriginal As New DataSet
CreateSchema(dsOriginal)
dsOriginal.Tables("FatherTable").Rows.Add(New Object() {"Father1",
"Col1"})
dsOriginal.AcceptChanges()
Return dsOriginal
End Function
Sub WorkWithDataset(ByVal WorkingDataSet As DataSet)
WorkingDataSet.Tables("FatherTable").Rows(0).Delete()
WorkingDataSet.Tables("FatherTable").Rows.Add(New Object()
{"Father1", "ColChanged"})
WorkingDataSet.Tables("ChildTable").Rows.Add(New Object()
{"Father1", "Child1"})
End Sub
Sub Main()
'dsOriginal is the server copy
Dim dsOriginal As DataSet = CreateOriginalDataset()
'dsWorking is the client copy
'starts off with original copy
Dim dsWorking As DataSet = dsOriginal.Copy
'client copy is modified
WorkWithDataset(dsWorking)
'get changes to send to the server<===
Dim dsChanges As DataSet = dsWorking.GetChanges
'persist out the changes (remoting process) <===
dsChanges.WriteXml("myFileName.xml", XmlWriteMode.DiffGram)
'read back in the changes (remoting processs) <===
Dim dsRead As New DataSet
CreateSchema(dsRead)
dsRead.ReadXml("myFileName.xml", XmlReadMode.DiffGram)
'merge client side changes to the server copy
dsOriginal.Merge(dsRead.GetChanges)
dsOriginal.AcceptChanges()
Console.WriteLine("")
Console.WriteLine("****
ORIGINAL*****************************************************")
Console.WriteLine("")
dsOriginal.WriteXml(Console.Out)
Console.WriteLine("")
Console.WriteLine("**** WORKING
*****************************************************")
Console.WriteLine("")
dsWorking.WriteXml(Console.Out)
Console.ReadLine()
End Sub
Excuse I am late. I live in Brazil and here has carnival (4 days). In Rio it
is very famous. Do you like carnival?
Let's go to work.
Imagine a server giving the dataset to a client application. The client
binds this dataset to a datagrid. The client user deletes the father row and,
afterwards, decides to create the same row again. What the client must return
to the server? Isn't the dataset.GetChanges?
I would like to say when a return the dataset.GetChanges to a local method,
it works ok, but if I return to a remote server by remoting, it doesn't work
(the child row vanishes) and I think the serialization doesn't work ok in
this case.
I change your example program again (the code is above) creating a new
column in father table. You will see that the father row was inserted, but
there is no child.
Code:
Sub CreateSchema(ByVal InDS As DataSet)
Dim FatherTable As New DataTable("FatherTable")
Dim ChildTable As New DataTable("ChildTable")
Dim fatherCol1 As New DataColumn("FatherCol1")
'I create a new column in father table
Dim fatherCol2 As New DataColumn("FatherCol2")
Dim childCol1 As New DataColumn("ChildCol1")
Dim childCol2 As New DataColumn("ChildCol2")
FatherTable.Columns.Add(fatherCol1)
FatherTable.Columns.Add(fatherCol2)
ChildTable.Columns.Add(childCol1)
ChildTable.Columns.Add(childCol2)
FatherTable.PrimaryKey = New DataColumn() {fatherCol1}
InDS.Tables.Add(FatherTable)
InDS.Tables.Add(ChildTable)
InDS.Relations.Add("FatherChildRelation", fatherCol1, childCol1)
End Sub
Function CreateOriginalDataset() As DataSet
Dim dsOriginal As New DataSet
CreateSchema(dsOriginal)
dsOriginal.Tables("FatherTable").Rows.Add(New Object() {"Father1",
"Col1"})
dsOriginal.AcceptChanges()
Return dsOriginal
End Function
Sub WorkWithDataset(ByVal WorkingDataSet As DataSet)
WorkingDataSet.Tables("FatherTable").Rows(0).Delete()
WorkingDataSet.Tables("FatherTable").Rows.Add(New Object()
{"Father1", "ColChanged"})
WorkingDataSet.Tables("ChildTable").Rows.Add(New Object()
{"Father1", "Child1"})
End Sub
Sub Main()
'dsOriginal is the server copy
Dim dsOriginal As DataSet = CreateOriginalDataset()
'dsWorking is the client copy
'starts off with original copy
Dim dsWorking As DataSet = dsOriginal.Copy
'client copy is modified
WorkWithDataset(dsWorking)
'get changes to send to the server<===
Dim dsChanges As DataSet = dsWorking.GetChanges
'persist out the changes (remoting process) <===
dsChanges.WriteXml("myFileName.xml", XmlWriteMode.DiffGram)
'read back in the changes (remoting processs) <===
Dim dsRead As New DataSet
CreateSchema(dsRead)
dsRead.ReadXml("myFileName.xml", XmlReadMode.DiffGram)
'merge client side changes to the server copy
dsOriginal.Merge(dsRead.GetChanges)
dsOriginal.AcceptChanges()
Console.WriteLine("")
Console.WriteLine("****
ORIGINAL*****************************************************")
Console.WriteLine("")
dsOriginal.WriteXml(Console.Out)
Console.WriteLine("")
Console.WriteLine("**** WORKING
*****************************************************")
Console.WriteLine("")
dsWorking.WriteXml(Console.Out)
Console.ReadLine()
End Sub