Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VS2015 - WPF - ADO.NET - ACCESS

I encounter a blocking behevior when committing a new order for a customer in a Master/Details relationship through two DataGrid.

When I add a customer in the last empty row of the Master DataGrid, and then add for that customer an order in the Details Datagrid on the last empty row of the control, on the commit event through a save button, the application erases the content of the Details DataGrid despate the fact that the orders DataView and DataTable have taken into acount the newly added child row.

I follow the execution path and find out that the problem is tied to the update cascading rule of the customers table's TableAdapter, when updating is taking place in order to assign the ID of the customer to the foreigner key of the child order row in the RowUpdated event.

Before execution of the commit phase
https://www.developpez.net/forums/attachments/p285711d1497481807/dotnet/developpement-windows/windows-presentation-foundation/wpf-ado-net-effacement-commandes-consolidation-7/capture-.png

During the commit phase
https://www.developpez.net/forums/attachments/p285715d1497481833/dotnet/developpement-windows/windows-presentation-foundation/wpf-ado-net-effacement-commandes-consolidation-7/capture-pendant.png/

After the commit
https://www.developpez.net/forums/attachments/p285719d1497481862/dotnet/developpement-windows/windows-presentation-foundation/wpf-ado-net-effacement-commandes-consolidation-7/capture-apres.png/

I really don't know how to solve this problem ending searching helpfull links on internet:

https://stackoverflow.com/questions/24147924/wpf-master-details-new-data-disappears-from-datagrid

https://connect.microsoft.com/VisualStudio/feedback/details/538103/wpf-dataset-master-detail-binding-issue

Code of the RowUpdated méthod :

private void dataadapterClients_RowUpdated(object sender, OdbcRowUpdatedEventArgs args)
        {
            if (args.RecordsAffected > 0)
            {
                if (args.StatementType == StatementType.Insert)
                {
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Attibue un numero d'ordre au client nouvellement cree");

                    OdbcCommand cmdIdentity = new OdbcCommand("SELECT @@IDENTITY", args.Command.Connection);
                    cmdIdentity.Transaction = Transaction;
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Avant numerotation automatique du client");
                    int id = (int)(cmdIdentity.ExecuteScalar());
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Client_ID : " + id);
                    args.Row.Table.Columns["Client_ID"].ReadOnly = false;
                    args.Row.Table.DataSet.Tables["Commandes"].Columns["Client_ID"].ReadOnly = false;
                    MessageBox.Show("Stop ??????????????????");
                    args.Row["Client_ID"] = id;
                    args.Row.Table.Columns["Client_ID"].ReadOnly = true;
                    args.Row.Table.DataSet.Tables["Commandes"].Columns["Client_ID"].ReadOnly = true;
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Apres numerotation automatique du client");
                }
                if (args.StatementType == StatementType.Insert || args.StatementType == StatementType.Update)
                {
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Recuperation de l'horodatage de la ligne client. Type d'ordre : " + args.StatementType);

                    int intCriteria = 0;
                    if (args.StatementType == StatementType.Insert)
                        intCriteria = (int)args.Row["Client_ID"];
                    else
                        intCriteria = (int)args.Row["Client_ID", DataRowVersion.Original];
                    OdbcCommand cmdStamp = new OdbcCommand("SELECT Stamp FROM Clients WHERE Client_ID = " + intCriteria, args.Command.Connection);
                    cmdStamp.Transaction = Transaction;
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Avant ExecuteScalar");
                    DateTime dteStamp = (DateTime)(cmdStamp.ExecuteScalar()); // DateTime.Now
                    Console.WriteLine("[DBWpf, ClientsTableAdapter] dataadapterClients_RowUpdated, Horodatage : " + dteStamp);
                    args.Row.Table.Columns["Stamp"].ReadOnly = false;
                    args.Row["Stamp"] = dteStamp;
                    args.Row.Table.Columns["Stamp"].ReadOnly = true; // true
                }
            }
            else
            {
                // args.Row.RowError = "Conflit d'acces concurrentiel optimiste rencontre"; // Concurrency Violation Encountered
                // args.Status = UpdateStatus.SkipCurrentRow;
            }
        }


The problem raises on execution of the instruction that follows the MessageBox.Show() which initializes the ID of the newly added customer and propages the update (Update Rule Cascade) to the child row.

MessageBox.Show("Stop ??????????????????");
args.Row["Client_ID"] = id;


The "TwoWay Binding" of WPF should update the UI, but in this case, the content of the Details DataGrid is erased.

That is why I would like to give here a download link to my project in order to let you see precisely the problem by executing the application I wrote, and may be able to figure out a solution to my problem.

https://drive.google.com/file/d/0B64EJCynJGIza1J1ZF9PcTNKTHM/view?usp=sharing

Thanks for your help
.

What I have tried:

https://social.msdn.microsoft.com/Forums/en-US/261c9f33-9afe-4549-b7cb-5b638741d5ce/adonet-masterdetail-wpf-detail-datagrid-erased-on-rowupdated-event?forum=netfxbcl
Posted
Updated 11-Jul-17 10:14am
v7
Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900