I am trying to find out if a DataTable object has any changes that need to be saved to it's 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.
Does anyone know why this is Or better yet, anyone know how I can accomplish what I am trying to do

Problem with GetChanges() from a DataTable Object
Jakein2006
Ok...here is my code line that crashes...
Me.DataSet.Tables("tblCodes").GetChanges().Rows.Count > 0 ThenThe Objects are as follows:
Me = Form
DataSet = Custom DataSet Object (Inheriting From System.Data.DataSet)
Tables("tblCodes") = Custom DataTable Object (Inheriting From System.Data.DataTable)
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
hawash
The only time I call Update() is when I click the Done button on my form, or in another routine I have that switches data viewed in the grid, which happens AFTER this portion of code that is crashing. So in answer to your question, before this line of code runs, Update() has not been called.
And also I do not use AcceptChanges() anywhere.
Could there possibly be some sort of problem because I am using Custom versions of the DataSet & DataTable object Could the inherited object I am using not properly inheriting the HasChanges() and GetChanges() methods
dev_bih
seco
IBRAHIM ERSOY
Try breaking out your code...something along these lines should work:
' Create variable for temporary DataSet.
Dim changesDataSet As DataSet If Me.dataSet.HasChanges() Then changesDataSet = DataSet.GetChanges() End IfIf Me.changesDataSet.Tables("tblCodes").Rows.Count > 0 Then
You can also use the row state parameter to get specific types of changes
wbrogdo1
jk67
NZ
Ok, since no one had an answer I continued my search. After digging for what seemed like forever, I figured out what was happening, so for those people encountering the same problem, here is your solution...
There is a few things GetChanges() does in order to return a DataTable filled with modified rows. The first thing it does is call Clone(). This method creates a new instance of the original DataTable, along with all the fields within the table. It then uses this empty DataTable and fills it with all the rows that have been modified and returns that back to the calling line of code.
Problem is that when Clone() is called, it instantiates a new copy of the object, using the Parameterless Constructor New() of the object. If you did not define this constructor, then you encounter the error "MissingMethodException was unhandled. No parameterless constructor defined for this object." Now in my case, I could not allow my derived DataTable to instantiate without the parameters I set in the Constructor, so how was I going to get this to work I thought. Well this is how.
I overrode the Clone() method of my derived DataTable, I then created a new instance of the same derived DataTable using the Activator.CreateInstance() method, and I passed to it the ObjectType and an Array with all the parameters needed. This insures that your class is recreated using the Parametric Contructor you forst designed. Now that you have a new derived DataTable that is identical to the current DataTable (minus the data) you have to create the fields. So I created a simple For Each loop that iterated through the Me.Columns collection, and added them to the cloned table (ObjClonedTable.Columns.Add(objOriginalTable.ColumnName, objOriginalTable.DataType)). Once this was done, you return the cloned table, and there, you are done.
Mapa3matuk