Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataTable.GetChanges() Crashes...
Message
From
03/02/2007 12:09:50
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01189575
Message ID:
01192112
Views:
20
Ben,

We use custom DataSets too, but we have all the constructors ... maybe I'm being dense, but I don't see why you would have a DataTable class defined with parameters. How are you defining your DataSets? Are you using Typed DataSets?

In regards to the second issue of the .HasChanges() not being true .. that one has to do with the need for calling the .EndEdit() on a Proposed change like I mentioned in my previous post.

~~Bonnie



>Bonnie,
>
>After doing some more digging I figured out why the DataTable.GetChanges was crashing. Apparently it's a way that Microsoft set up the inner workings of the GetChanges() method. Unfortunatly, it leaves a pretty large hole in the Logic (or security) of your derived class object. Let me explain...
>
>When GetChanges() is called from a DataTable object, it immediately calls the Clone() method. The Clone() method creates a new object of the same type, using the Parameterless Constructor of said object. If you do not have a Parameterless Contructor defined in your derived class, then you crash with an error stating "No parameterless constructor defined for this object." Now, adding a Parameterless Constructor does fix this problem, but...and here is the kicker, now you just opened up the possibility of this object being instantiated without the parameters that you were previously enforcing.
>
>So my question to you, and anyone else who is reading this, is the following. Is there a way to either be "aware" during the use of the Parameterless Contructor that it is being run because of a Clone() method call, in other words is there something like an IsCurrentlyCloning flag somewhere (which I doubt)? Or is there a way to force the use of the Parametric Constructor through the overriding of Clone() and/or maybe CreateInstance()? I am trying to figure out if there is a way to ensure that this object cannot be instantiated without the needed parameters...but right now I don't see a way of doing that.
>
>
>P.S. I still don't know why HasChanges() on the DataSet object still returns False always. I'll let you know if I figure that one out.
>
>>Ben,
>>
>>Sorry for the slow reply ... I've been out of the country and still trying to catch up since my return. I'm surprised that no one else has addressed your question.
>>
>>The problem with the DataSet.HasChanges() returning false when there are really changes is because of the problem with the proposed changes not having been committed yet.
>>
>>Data in a DataRow has several different versions. First, there's the original version. Then, when it's being edited, it becomes a Proposed version and once it's done being edited it becomes the Current version. Sometimes when editing, the row is left in the Proposed state and needs to be ended.
>>
>>Here's a method I *always* call before I attempt to save data:
>>
>>
>>protected virtual void CommitProposedChanges(DataSet ds)
>>{
>>	if (ds == null)
>>		return;
>>
>>	for (int nTable = 0; nTable < ds.Tables.Count; nTable++)
>>	{
>>		for (int nRow = 0; nRow < ds.Tables[nTable].Rows.Count; nRow++)
>>		{
>>			if (ds.Tables[nTable].Rows[nRow].HasVersion(DataRowVersion.Proposed))
>>			{
>>				ds.Tables[nTable].Rows[nRow].EndEdit();
>>			}
>>		}
>>	}
>>}
>>
>>
>>As far as your problem with DataTable.GetChanges(), I'm not sure why it crashed, but I pretty much always use DataSet.GetChanges() instead.
>>
>>~~Bonnie
>>
>>
>>
>>>I have a DataGridView that is bound to a DataTable. I am trying to find out if the DataTable object has any changes that need to be saved to its SQL Database using the Update() method. I looked throughout the properties of the DataTable object and can't find a Dirty property. But I did find a GetChanges() method. Problem is whenever I execute the GetChanges() method, which claims to return a DataTable of records that have been modified, I get the following error:
>>>
>>>     MissingMethodException was unhandled
>>>
>>>     No parameterless constructor defined for this object.
>>>
>>>Here is my code line that crashes...
>>>
>>>If Me.DataSet.Tables("tblCodes").GetChanges().Rows.Count > 0 Then
>>>
>>>
>>>I also tried utilizing the Me.DataSet.HasChanges(), but it always returns a FALSE, even when changes have been made to the Table(s) inside the DataSet. I am also not using AcceptChanges() anywhere. The Objects from the above line of code are as follows:
>>>     Me = Form
>>>     DataSet = Custom DataSet Object (Inheriting From System.Data.DataSet)
>>>     Tables("tblCodes") = Custom DataTable Object (Inheriting From System.Data.DataTable)
>>>
>>>Could there possibly be some sort of problem because I am using Custom versions of the DataSet & DataTable object? Could it be that the inherited objects I am using are not properly inheriting the HasChanges() and GetChanges() methods?
>>>
>>>All I need to know is if ANY changes have been made to the Table that have not been pushed up to the SQL Database yet. Any ideas?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform