none
Typed DataSet RRS feed

  • Question

  • I have a WPF grid from Component One that is connected to the default view of table A in a typed dataset. Each row in the grid has a related record stored in another table B. The values stored in table B are computed based on the table A record. When I add a record to A, I need to add the computed record to table B. When I update some fields of A, related computed fields in B need to be updated.

    I am coming from VB6.  My coding is targeted at a very small audience and concurrency problems are generally moot. Previously, I attached the code to update the B records in the grid events in VB6. One issue I have with the WPF grid and typed dataset is that the change events that I am trying to attach to fire both when the user makes changes and when the data is loaded. They also fire when I do a table adapter update.   It is hard to nail down the correct time to do the update of table B and I do not want it to occur multiple times.

    Also I do not want to have add and update buttons to create records and push the data from the dataset back to the SQL database.  I am trying to do table adapter updates whenever a row changes.  I know having the buttons would limit the number of table adapter updates required.  It would also allow me to manually add a row and determine the primary key of the added row.  My users are used to being able to just add a new row by going to the bottom of the grid to the new row placeholder.  They are used to changing rows to update data.

    I have tried creating a data provider and adding handlers for RowChanging and RowChanged but I have not been able to catch the point where the primary key for record A gets assigned

    I was able to customize the typed dataset by overriding OnColumnChanging and OnColumnChanged.  However, the code to update table B ends up getting run multiple times for one row update when it could have been run just once.

    Anyone have an idea on how to handle this?

    I am thinking there should be a way to create code on the SQL server side to handle the table B updates automatically.

    I am wondering if ADO.NET Entity Data Model or the LINQ to SQL Classes would work better?

    Thanks for any insight you can offer.

    Tuesday, November 1, 2011 4:37 PM

Answers

  • hello,

    you have given much details of your problem that is really appreciable.

    From that I understand that you want to make changes in table B automatically once you made any changes in table A. if you are not showing up table B data to your WPF application then I suggest you should do all these work on sql server.

    In your stored procedure of table A, you  can write code to make changes in table B. table A's stored procedure will be fired when you commit changes from your adapter and underlying code will update to your table B.

    hope, this can be a bit helpful to your problem.

     

     


    Thanks and Regards, Shailesh B. Davara
    Tuesday, November 8, 2011 9:25 AM

All replies

  • Hi TGMVA,

    Welcome!

    I think you can try to use Stored procedure to reassign the primary key, you should set "Update Rule" to Cascade.

    BTW, If I misunderstood you, please feel free to let me know.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, November 2, 2011 8:27 AM
    Moderator
  • I am not certain I understand.  I will try looking at stored procedures.  I am thinking there are ways to "trigger" these such as when a record is added or updated in table A.  In the typed dataset, I have both table A and B and they are set to cascade updates and deletes.  However, I am trying to set a field in table B equal to a computation based on table A values.  Intuitively, it would seem like there might be another way to handle the data (combine tables or that I should just recompute the value each time I need it) but this would require substancial reworking of an existing program and data that I am trying to port from VB6 to VB 2010.

    Basically, either on the server or client side, I need to detect when a row is added or updated in A and update or add records to table B.

     

    Thanks.

    Wednesday, November 2, 2011 12:54 PM
  • hello,

    you have given much details of your problem that is really appreciable.

    From that I understand that you want to make changes in table B automatically once you made any changes in table A. if you are not showing up table B data to your WPF application then I suggest you should do all these work on sql server.

    In your stored procedure of table A, you  can write code to make changes in table B. table A's stored procedure will be fired when you commit changes from your adapter and underlying code will update to your table B.

    hope, this can be a bit helpful to your problem.

     

     


    Thanks and Regards, Shailesh B. Davara
    Tuesday, November 8, 2011 9:25 AM