Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataTable.GetChanges() Crashes...
Message
 
À
30/01/2007 12:23:50
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01189575
Message ID:
01191821
Vues:
14
Bonnie,

Thank you for responding, I was out sick for the past few days so I wasn't able to try your suggestion until today. I must say I was very excited to try it. Alas, I have bad news...it didn't work. After stepping through the code, I saw that even when I changed a row's data, it never "flagged" itself as a DataRowVersion.Proposed, so the code never executed the line with the EndEdit() method. Apparently I am back at square one. This problem is really boggling my mind...I just don't understand why it refuses to work.

>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?
________________________
Ben Santiago, MCP & A+
Programmer Analyst (SQL, FoxPro, VB, VB.Net, Java, HTML, ASP, JSP, VBS)
Eastern Suffolk BOCES - Student Data Services


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rich Cook
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform