PC Review


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

DataSet.Merge() does not merge row and/or column errors in any cas

 
 
=?Utf-8?B?SGFucyBXZWJlcg==?=
Guest
Posts: n/a
 
      16th Dec 2005
I save changes from a dataset and get them with

tempDataSet = myDataSet.GetChanges()

I validate the changed rows and if I find an error, I mark the row with

tempDataSet.DataTable.Row[..].SetColumnError(...)

coming back from validation, tempDataSet.HasErrors is true, that's ok.

Then I merge the datas for giving back the errors:

myDataSet.Merge(tempDataSet)

Unfortunately in some cases myDataSet.HasError is then false, though there
is still an error. Does any one know how to force the Merge method to copy
also the error settings of the dataset to merge in every case?

PS. This error occurs mostly when there is a parent-child relation between
two tables. If the parent row is added without child, the error is reported
to myDataSet. If the errorneous parent row has one child, the errorsetting of
parent row is not merged into myDataSet. Once again: tempDataSet returns
ALWAYS with HasErrors=true, when SetErrror has been executed.





 
Reply With Quote
 
 
 
 
Sahil Malik [MVP C#]
Guest
Posts: n/a
 
      17th Dec 2005
DataSet.Merge is a bit weird. There are two things that govern the output
result

a) Who is the boss. Ds1.Merge(ds2) <-- ds1 is the boss.
b) What schema information have you specified?

Regards the HasErrors - without actually writing up code at my end, I would
try specifying Primary Keys on both Ds1 and Ds2, and try once again - if it
still eats up the errors .. uhhh .. bad luck .
I vaguely remember having this problem myself, I am inclined to say that I
reversed the direction of the merge ds2.merge(ds1) and got out of it - but
if both sides have errors, then you're screwed. But this is such an isolated
case that I would write code to verify this statement.

Anyway, I vaguely recollecting facing this problem myself, so not much I
could add.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
__________________________________________________________


"Hans Weber" <Hans (E-Mail Removed)> wrote in message
news:83DD4AFB-47FD-427C-87D0-(E-Mail Removed)...
>I save changes from a dataset and get them with
>
> tempDataSet = myDataSet.GetChanges()
>
> I validate the changed rows and if I find an error, I mark the row with
>
> tempDataSet.DataTable.Row[..].SetColumnError(...)
>
> coming back from validation, tempDataSet.HasErrors is true, that's ok.
>
> Then I merge the datas for giving back the errors:
>
> myDataSet.Merge(tempDataSet)
>
> Unfortunately in some cases myDataSet.HasError is then false, though there
> is still an error. Does any one know how to force the Merge method to copy
> also the error settings of the dataset to merge in every case?
>
> PS. This error occurs mostly when there is a parent-child relation between
> two tables. If the parent row is added without child, the error is
> reported
> to myDataSet. If the errorneous parent row has one child, the errorsetting
> of
> parent row is not merged into myDataSet. Once again: tempDataSet returns
> ALWAYS with HasErrors=true, when SetErrror has been executed.
>
>
>
>
>



 
Reply With Quote
 
=?Utf-8?B?SGFucyBXZWJlcg==?=
Guest
Posts: n/a
 
      19th Dec 2005
Hi Sahil
Thanks for your answer.

I checked my schema definitions and I guess they are correct. If you want
you can have a look on them. I added schema definitions (xsd) after this
text. It is just a simple master-detail relation with invoices and the
invoice positions. The boss is Ds1. I can't merge it by the Ds2.Merge(Ds1),
because some navigators and error providers are connected with Ds1.

Once again: ds2 returns always with the correct error setting and returns
with ds.HasErrors = true. It is after the Ds1.Merge(ds2) that Ds1.HasErrors
has unfortunately false. If there is no workaround I will make by my self a
procedure that copies the errors form Ds2 to Ds1.

Thanks
Hans Weber

InvoiceDataSet.cs
------------------------
private void InitClass() {
this.DataSetName = "InvoiceDataSet";
this.Prefix = "";
this.Namespace = "http://xxx/Rmg/InvoiceDataSet";
this.Locale = new System.Globalization.CultureInfo("de-CH");
this.CaseSensitive = false;
this.EnforceConstraints = true;
this.tableInvoice = new InvoiceDataTable();
this.Tables.Add(this.tableInvoice);
this.tableInvoicespositionX = new InvoicespositionXDataTable();
this.Tables.Add(this.tableInvoicespositionX);
ForeignKeyConstraint fkc;
fkc = new ForeignKeyConstraint("Invoice_Invoicesposition", new
DataColumn[] {
this.tableInvoice.RecUIDColumn}, new DataColumn[] {
this.tableInvoicespositionX.RecIDColumn});
this.tableInvoicespositionX.Constraints.Add(fkc);
fkc.AcceptRejectRule = System.Data.AcceptRejectRule.None;
fkc.DeleteRule = System.Data.Rule.Cascade;
fkc.UpdateRule = System.Data.Rule.Cascade;
this.relationInvoice_Invoicesposition = new
DataRelation("Invoice_Invoicesposition", new DataColumn[] {
this.tableInvoice.RecUIDColumn}, new DataColumn[] {
this.tableInvoicespositionX.RecIDColumn}, false);
this.Relations.Add(this.relationInvoice_Invoicesposition);
}

InvoiceDataSet.xsd
-------------------------

<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="InvoiceDataSet"
targetNamespace="http://xxx/Rmg/InvoiceDataSet"
xmlns:mstns="http://xxx/Rmg/InvoiceDataSet"
xmlns="http://xxx/Rmg/InvoiceDataSet"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified"
xmlns:app1="http://xxx/Rmg/Invoice"
xmlns:app2="http://xxx/Rmg/InvoicespositionX">
<!--ATTENTION: This schema contains references to other imported schemas-->
<xs:import namespace="http://xxx/Rmg/Invoice"
schemaLocation="Rmg/Invoice_table.xsd" />
<xs:import namespace="http://xxx/Rmg/InvoicespositionX"
schemaLocation="Rmg/InvoicespositionX_table.xsd" />
<xs:element name="InvoiceDataSet" msdata:IsDataSet="true"
msdata:Locale="de-CH">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="app1:Invoice" />
<xs:element ref="app2:InvoicespositionX" />
</xs:choice>
</xs:complexType>
<xs:unique name="InvoicePK" msdata:PrimaryKey="true">
<xs:selector xpath=".//app1:Invoice" />
<xs:field xpath="app1:RecUID" />
</xs:unique>
<xs:unique name="InvoicespositionXPK" msdata:PrimaryKey="true">
<xs:selector xpath=".//app2:InvoicespositionX" />
<xs:field xpath="app2:RcpUID" />
</xs:unique>
<xs:keyref name="Invoice_Invoicesposition" refer="InvoicePK">
<xs:selector xpath=".//app2:InvoicespositionX" />
<xs:field xpath="app2:RecID" />
</xs:keyref>
</xs:element>
</xs:schema>

Invoice_table.xsd
---------------------

<?xml version="1.0"?>
<xs:schema xmlns="http://xxx/Rmg/Invoice"
targetNamespace="http://xxx/Rmg/Invoice"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="Invoice_type.xsd" />
<xs:element name="Invoice" type="InvoiceType" />
</xs:schema>


Invoiceposition_table.xsd
--------------------------------

<?xml version="1.0"?>
<xs:schema xmlns="http://xxx/Rmg/Invoicesposition"
targetNamespace="http://xxx/Rmg/Invoicesposition"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="Invoicesposition_type.xsd" />
<xs:element name="Invoicesposition" type="InvoicespositionType" />
</xs:schema>

Invoice_type.xsd
-------------------------

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="InvoiceType">
<xs:sequence>
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="RecUID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="OrgID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="NacID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="MwstID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element name="RecNummer">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RecEingangsdatum" type="xs:dateTime" />
<xs:element name="RecDatum" type="xs:dateTime" />
<xs:element name="RecMonat" type="xs:short" />
<xs:element name="RecJahr" type="xs:short" />
<xs:element name="RecFolgeNr" type="xs:int" />
<xs:element name="RecBetrag" type="xs:decimal" />
<xs:element minOccurs="0" name="RecBemerkung">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="4000" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RecCreatedBy">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="128" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RecCreatedAt" type="xs:dateTime" />
<xs:element minOccurs="0" name="RecChangedBy">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="128" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" name="RecChangedAt" type="xs:dateTime" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="RecChangeSeq" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Invoiceposition_type.xsd
-----------------------------

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="InvoicespositionType">
<xs:sequence>
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="RcpUID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="RecID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="AufID" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element name="RcpNummer" type="xs:int" />
<xs:element name="RcpBetrag" type="xs:decimal" />
<xs:element minOccurs="0" name="RcpBemerkung">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="4000" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RcpCreatedBy">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="128" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RcpCreatedAt" type="xs:dateTime" />
<xs:element minOccurs="0" name="RcpChangedBy">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="128" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" name="RcpChangedAt" type="xs:dateTime" />
<xs:element msdataataType="System.Guid, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="RcpChangeSeq" type="xs:string"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
</xs:sequence>
</xs:complexType>
</xs:schema>

"Sahil Malik [MVP C#]" wrote:

> DataSet.Merge is a bit weird. There are two things that govern the output
> result
>
> a) Who is the boss. Ds1.Merge(ds2) <-- ds1 is the boss.
> b) What schema information have you specified?
>
> Regards the HasErrors - without actually writing up code at my end, I would
> try specifying Primary Keys on both Ds1 and Ds2, and try once again - if it
> still eats up the errors .. uhhh .. bad luck .
> I vaguely remember having this problem myself, I am inclined to say that I
> reversed the direction of the merge ds2.merge(ds1) and got out of it - but
> if both sides have errors, then you're screwed. But this is such an isolated
> case that I would write code to verify this statement.
>
> Anyway, I vaguely recollecting facing this problem myself, so not much I
> could add.
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> __________________________________________________________
>
>
> "Hans Weber" <Hans (E-Mail Removed)> wrote in message
> news:83DD4AFB-47FD-427C-87D0-(E-Mail Removed)...
> >I save changes from a dataset and get them with
> >
> > tempDataSet = myDataSet.GetChanges()
> >
> > I validate the changed rows and if I find an error, I mark the row with
> >
> > tempDataSet.DataTable.Row[..].SetColumnError(...)
> >
> > coming back from validation, tempDataSet.HasErrors is true, that's ok.
> >
> > Then I merge the datas for giving back the errors:
> >
> > myDataSet.Merge(tempDataSet)
> >
> > Unfortunately in some cases myDataSet.HasError is then false, though there
> > is still an error. Does any one know how to force the Merge method to copy
> > also the error settings of the dataset to merge in every case?
> >
> > PS. This error occurs mostly when there is a parent-child relation between
> > two tables. If the parent row is added without child, the error is
> > reported
> > to myDataSet. If the errorneous parent row has one child, the errorsetting
> > of
> > parent row is not merged into myDataSet. Once again: tempDataSet returns
> > ALWAYS with HasErrors=true, when SetErrror has been executed.
> >
> >
> >
> >
> >

>
>
>

 
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
DataSet.Merge and Column.Expression tomb Microsoft ADO .NET 3 20th May 2005 01:00 AM
DataSet.Merge where data being merge has less rows than the oringal source Dan Hibbert Microsoft ADO .NET 2 20th Jan 2005 06:35 PM
DataSet.Merge with Column.Expression. expression not =?Utf-8?B?R2llZHJpdXM=?= Microsoft ADO .NET 4 12th Jan 2005 09:45 AM
Dataset merge with subset of another dataset table moondaddy Microsoft ADO .NET 1 14th Sep 2004 05:05 PM
Re: DataSet.Merge: DataSet.HasChanges returns true Markus Wildgruber Microsoft ADO .NET 6 4th Sep 2003 01:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:00 AM.