PC Review


Reply
Thread Tools Rate Thread

DataTable RowChanging event occurs in Fill with EnforceConstraints

 
 
=?Utf-8?B?RGFuaWVsIEdyYXNzaWNr?=
Guest
Posts: n/a
 
      10th Dec 2006
Msdn documentation states that setting DataSet EnforceConstraints to false
should prevent RowChanging event from firing when the table is filled but it
does fire. Is this a bug?

My example is a simple Windows Forms application created by drag and drop to
display the contents of a simple SQL Server table in a DataGridView. The form
code is as follows:

private TestDataSet.TestTableDataTable mfldTestTable;

public FormTest()
{
InitializeComponent();

mfldTestTable = mctlTestDataSet.TestTable;
mfldTestTable.RowChanging += new
DataRowChangeEventHandler(mfldTestTable_RowChanging);
}

private void FormTest_Load(object sender, EventArgs e)
{
mctlTestDataSet.EnforceConstraints = false;
this.mctlTestTableTableAdapter.Fill(this.mctlTestDataSet.TestTable);
mctlTestDataSet.EnforceConstraints = true;
}

private void mfldTestTable_RowChanging(object sender, DataRowChangeEventArgs
e)
{
// Do Stuff
}

Thanks for any clarification regarding this matter.

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10th Dec 2006
Hi David,

I don't know where you're getting your information from, but I certainly
can't find such a remark on the MSDN .Net SDK. Looking at
http://msdn2.microsoft.com/en-us/lib...nstraints.aspx, I
see that the property does what it logically would seem to do: It prevents
the enforcing of constraints while it is true. This does NOT mean that it
prevents any changes to any elements contained in it, NOR does it mean that
the "changed" events for those elements will not fire. What it DOES mean is
that if any change Constraint is violated during a change, a
ConstraintException will not be fired.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Daniel Grassick" <(E-Mail Removed)> wrote in message
news:9E64514B-29B1-485B-8491-(E-Mail Removed)...
> Msdn documentation states that setting DataSet EnforceConstraints to false
> should prevent RowChanging event from firing when the table is filled but
> it
> does fire. Is this a bug?
>
> My example is a simple Windows Forms application created by drag and drop
> to
> display the contents of a simple SQL Server table in a DataGridView. The
> form
> code is as follows:
>
> private TestDataSet.TestTableDataTable mfldTestTable;
>
> public FormTest()
> {
> InitializeComponent();
>
> mfldTestTable = mctlTestDataSet.TestTable;
> mfldTestTable.RowChanging += new
> DataRowChangeEventHandler(mfldTestTable_RowChanging);
> }
>
> private void FormTest_Load(object sender, EventArgs e)
> {
> mctlTestDataSet.EnforceConstraints = false;
> this.mctlTestTableTableAdapter.Fill(this.mctlTestDataSet.TestTable);
> mctlTestDataSet.EnforceConstraints = true;
> }
>
> private void mfldTestTable_RowChanging(object sender,
> DataRowChangeEventArgs
> e)
> {
> // Do Stuff
> }
>
> Thanks for any clarification regarding this matter.
>



 
Reply With Quote
 
=?Utf-8?B?RGFuaWVsIEdyYXNzaWNr?=
Guest
Posts: n/a
 
      10th Dec 2006
Hi Kevin,

I guess I should have provided the references. In MSDN Library "How to: Turn
Off Constraints While Filling a Dataset"
http://msdn2.microsoft.com/en-us/library/s3bxwk8b(vs.80).aspx there is a note
after the opening paragraph that states "Validation events (for example,
ColumnChanging, RowChanging, and so on) will not be raised when constraints
are turned off." It would seem that this note is a "documentation bug"
because there is no mention in the documentation for EnforceConstraints.

Thanks for your reply. I guess I will just set an "IsTableFilled" flag to
skip validation during the table fill.

Daniel


"Kevin Spencer" wrote:

> Hi David,
>
> I don't know where you're getting your information from, but I certainly
> can't find such a remark on the MSDN .Net SDK. Looking at
> http://msdn2.microsoft.com/en-us/lib...nstraints.aspx, I
> see that the property does what it logically would seem to do: It prevents
> the enforcing of constraints while it is true. This does NOT mean that it
> prevents any changes to any elements contained in it, NOR does it mean that
> the "changed" events for those elements will not fire. What it DOES mean is
> that if any change Constraint is violated during a change, a
> ConstraintException will not be fired.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Logostician
> http://unclechutney.blogspot.com
>
> There is a madness to my method.
>
> "Daniel Grassick" <(E-Mail Removed)> wrote in message
> news:9E64514B-29B1-485B-8491-(E-Mail Removed)...
> > Msdn documentation states that setting DataSet EnforceConstraints to false
> > should prevent RowChanging event from firing when the table is filled but
> > it
> > does fire. Is this a bug?
> >
> > My example is a simple Windows Forms application created by drag and drop
> > to
> > display the contents of a simple SQL Server table in a DataGridView. The
> > form
> > code is as follows:
> >
> > private TestDataSet.TestTableDataTable mfldTestTable;
> >
> > public FormTest()
> > {
> > InitializeComponent();
> >
> > mfldTestTable = mctlTestDataSet.TestTable;
> > mfldTestTable.RowChanging += new
> > DataRowChangeEventHandler(mfldTestTable_RowChanging);
> > }
> >
> > private void FormTest_Load(object sender, EventArgs e)
> > {
> > mctlTestDataSet.EnforceConstraints = false;
> > this.mctlTestTableTableAdapter.Fill(this.mctlTestDataSet.TestTable);
> > mctlTestDataSet.EnforceConstraints = true;
> > }
> >
> > private void mfldTestTable_RowChanging(object sender,
> > DataRowChangeEventArgs
> > e)
> > {
> > // Do Stuff
> > }
> >
> > Thanks for any clarification regarding this matter.
> >

>
>
>

 
Reply With Quote
 
Linda Liu [MSFT]
Guest
Posts: n/a
 
      11th Dec 2006
Hi Daniel,

I agree with Kevin. Setting the EnforceConstraints property of a DataSet to
false only means that constraint rules are not followed when attempting any
update operation in the DataSet.

Even if the EnforceConstraints property is set to false, the ColumnChanging
or RowChanging will still be raised when any update operation is made.

If you don't want to raise the RowChanging/ColumnChanging event while
filling the DataTable, I suggest that you unsubscribe these events before
filling the DataTable and then subscribe these events again later.

The following is a sample.

// unsubscribe the RowChanging event
mfldTestTable.RowChanging -= new
DataRowChangeEventHandler(mfldTestTable_RowChanging);

// fill the data table
this.mctlTestTableTableAdapter.Fill(this.mctlTestDataSet.TestTable);

// subscribe the RowChanging event again
mfldTestTable.RowChanging += new
DataRowChangeEventHandler(mfldTestTable_RowChanging);

As for the MSDN document "How to: Turn
Off Constraints While Filling a Dataset"
http://msdn2.microsoft.com/en-us/library/s3bxwk8b(vs.80).aspx , it seems to
be incorrect. I will report this to our product team.

Thank you for pointing it out to us!

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11th Dec 2006
Hi Daniel,

The araticle you mentioned does seem at best misleading. It may be that when
you call the Fill method, the events are fired regardless. I just haven't
ever tried to find out. I use a similar technique to yours, by setting a
_Filling boolean while the table is filling.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Daniel Grassick" <(E-Mail Removed)> wrote in message
news:2BDA9928-FCA4-4CED-B368-(E-Mail Removed)...
> Hi Kevin,
>
> I guess I should have provided the references. In MSDN Library "How to:
> Turn
> Off Constraints While Filling a Dataset"
> http://msdn2.microsoft.com/en-us/library/s3bxwk8b(vs.80).aspx there is a
> note
> after the opening paragraph that states "Validation events (for example,
> ColumnChanging, RowChanging, and so on) will not be raised when
> constraints
> are turned off." It would seem that this note is a "documentation bug"
> because there is no mention in the documentation for EnforceConstraints.
>
> Thanks for your reply. I guess I will just set an "IsTableFilled" flag to
> skip validation during the table fill.
>
> Daniel
>
>
> "Kevin Spencer" wrote:
>
>> Hi David,
>>
>> I don't know where you're getting your information from, but I certainly
>> can't find such a remark on the MSDN .Net SDK. Looking at
>> http://msdn2.microsoft.com/en-us/lib...nstraints.aspx, I
>> see that the property does what it logically would seem to do: It
>> prevents
>> the enforcing of constraints while it is true. This does NOT mean that it
>> prevents any changes to any elements contained in it, NOR does it mean
>> that
>> the "changed" events for those elements will not fire. What it DOES mean
>> is
>> that if any change Constraint is violated during a change, a
>> ConstraintException will not be fired.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Logostician
>> http://unclechutney.blogspot.com
>>
>> There is a madness to my method.
>>
>> "Daniel Grassick" <(E-Mail Removed)> wrote in message
>> news:9E64514B-29B1-485B-8491-(E-Mail Removed)...
>> > Msdn documentation states that setting DataSet EnforceConstraints to
>> > false
>> > should prevent RowChanging event from firing when the table is filled
>> > but
>> > it
>> > does fire. Is this a bug?
>> >
>> > My example is a simple Windows Forms application created by drag and
>> > drop
>> > to
>> > display the contents of a simple SQL Server table in a DataGridView.
>> > The
>> > form
>> > code is as follows:
>> >
>> > private TestDataSet.TestTableDataTable mfldTestTable;
>> >
>> > public FormTest()
>> > {
>> > InitializeComponent();
>> >
>> > mfldTestTable = mctlTestDataSet.TestTable;
>> > mfldTestTable.RowChanging += new
>> > DataRowChangeEventHandler(mfldTestTable_RowChanging);
>> > }
>> >
>> > private void FormTest_Load(object sender, EventArgs e)
>> > {
>> > mctlTestDataSet.EnforceConstraints = false;
>> > this.mctlTestTableTableAdapter.Fill(this.mctlTestDataSet.TestTable);
>> > mctlTestDataSet.EnforceConstraints = true;
>> > }
>> >
>> > private void mfldTestTable_RowChanging(object sender,
>> > DataRowChangeEventArgs
>> > e)
>> > {
>> > // Do Stuff
>> > }
>> >
>> > Thanks for any clarification regarding this matter.
>> >

>>
>>
>>



 
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
DataTable Events - RowChanging =?Utf-8?B?RGVubmlz?= Microsoft VB .NET 2 15th Dec 2004 02:03 AM
How to set EnforceConstraints on a datatable? W.G. Rowland Microsoft ADO .NET 2 11th Sep 2004 07:36 PM
DataTable RowChanging problem with Row.Count Oka Morikawa Microsoft ADO .NET 3 11th May 2004 11:41 PM
Strange DataTable problem (with eventhandled rowchanging) Oka Morikawa Microsoft Dot NET Framework Forms 0 22nd Apr 2004 02:38 PM
Error when using rowchanging event in datatable AH Microsoft VB .NET 1 16th Dec 2003 12:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 PM.