Solved

Pivot datatable for GridView and Update

Posted on 2012-03-27
2
785 Views
Last Modified: 2012-03-31
Hello, I have seen several articles on Pivoting data in a datatable to bind to a data grid.  Im using the one referenced in this link:

http://geekswithblogs.net/dotNETvinz/archive/2009/05/10/pivot-data-in-gridview---a-generic-pivot-method-with.aspx

I have the 2 datatables as in the example.

The original normalized version 'dt' with a sqldataadapter.
and the pivoted version 'pivotedTable' as the datasource for the gridview.

I would like to save the data modified in the gridview back to the database in its normalize form.  Possibly using the 'dt' datatable and dataadapter.  

My thoughts are:
use 'getchanges' from pivotedTable:

        Dim changedRecords As System.Data.DataTable
        changedRecords = dt.GetChanges

Then use 'changedrecords' datatable to update the original dt, and da.update to update the database.

My question is: is this a reasonable approach?, is there a better way?.  Does someone have an example.

Im using winforms and vb.net but c++ is ok also.

thanks very much.
0
Comment
Question by:sourcelink
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37774104
I think that is a reason able approach. Given that data in PivotedTable can not be saved back to the DB using adapter then you have two options

1) Getchanges and apply to dt then save dt using adapter
2) Getchanges, loop and save changes to db manually.
0
 

Author Comment

by:sourcelink
ID: 37791577
Thanks for your response.  This seem like it would be a fairly common request, but I havent been able to find anyone that has written someting similar.  I guess that is the path I will be taking. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now