Click here to Skip to main content
15,922,630 members
Home / Discussions / C#
   

C#

 
Generali want to know something Pin
snouto15-Mar-05 12:32
snouto15-Mar-05 12:32 
GeneralRe: i want to know something Pin
Christian Graus15-Mar-05 12:57
protectorChristian Graus15-Mar-05 12:57 
GeneralUsing the update command of the datagrid to alter the data in a dataset Pin
Anonymous15-Mar-05 12:18
Anonymous15-Mar-05 12:18 
GeneralReceiving SMS problem Pin
ccui15-Mar-05 10:18
ccui15-Mar-05 10:18 
GeneralDataGrid TableStyles Pin
dennista15-Mar-05 9:03
dennista15-Mar-05 9:03 
GeneralRe: DataGrid TableStyles Pin
Kodanda Pani15-Mar-05 18:06
Kodanda Pani15-Mar-05 18:06 
GeneralRe: DataGrid TableStyles Pin
dennista16-Mar-05 3:31
dennista16-Mar-05 3:31 
GeneralFile IO in Webservice gives Error Pin
James Poulose15-Mar-05 8:21
James Poulose15-Mar-05 8:21 
GeneralRe: File IO in Webservice gives Error Pin
TylerBrinks15-Mar-05 9:46
TylerBrinks15-Mar-05 9:46 
QuestionHow to create a shallow copy of List<T> ? Pin
Andres Coder15-Mar-05 7:50
Andres Coder15-Mar-05 7:50 
AnswerRe: How to create a shallow copy of List<T> ? Pin
leppie15-Mar-05 8:51
leppie15-Mar-05 8:51 
GeneralSending a web form as parameter Pin
see0715-Mar-05 7:45
see0715-Mar-05 7:45 
GeneralRe: Sending a web form as parameter Pin
Pushkar Pathak15-Mar-05 18:16
Pushkar Pathak15-Mar-05 18:16 
GeneralRe: Sending a web form as parameter Pin
see0716-Mar-05 11:59
see0716-Mar-05 11:59 
GeneralRe: Sending a web form as parameter Pin
see0722-Mar-05 7:00
see0722-Mar-05 7:00 
GeneralRe: Sending a web form as parameter Pin
see0722-Mar-05 12:20
see0722-Mar-05 12:20 
GeneralSystem.Timers problem Pin
sjhart15-Mar-05 7:17
sjhart15-Mar-05 7:17 
GeneralRe: System.Timers problem Pin
TylerBrinks15-Mar-05 8:20
TylerBrinks15-Mar-05 8:20 
GeneralPassing Safearray parameter to WebBrowser COM component Pin
simcho9915-Mar-05 3:45
simcho9915-Mar-05 3:45 
QuestionHow to show a child form when parent form is busy? Pin
oohungoo15-Mar-05 3:25
oohungoo15-Mar-05 3:25 
AnswerRe: How to show a child form when parent form is busy? Pin
tdciDoug15-Mar-05 4:22
tdciDoug15-Mar-05 4:22 
GeneralRe: How to show a child form when parent form is busy? Pin
oohungoo15-Mar-05 19:18
oohungoo15-Mar-05 19:18 
AnswerRe: How to show a child form when parent form is busy? Pin
James Poulose15-Mar-05 8:24
James Poulose15-Mar-05 8:24 
GeneralPivot table in .net Pin
Prabhakar.A15-Mar-05 3:20
Prabhakar.A15-Mar-05 3:20 
GeneralRe: Pivot table in .net Pin
Ravindra Sadaphule15-Mar-05 5:33
Ravindra Sadaphule15-Mar-05 5:33 
Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc.

Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below.

The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table.


//Create Destination Table
DataTable dest = new DataTable("Pivot" );

// from each source table row (1st column)
// create a destination column
foreach( DataRow r in source.Rows )
dest.Columns.Add( r[0].ToString() );

// assign each row the Product name Now that we have the appropriate columns defined

in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name.
//Create columns in destination table for each row in source table.
for( int i = 0; i < source.Columns.Count - 1; i++ )
dest.Rows.Add( dest.NewRow() );


The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop.
//Transpose rows and columns
for( int r = 0; r < dest.Rows.Count; r++ )
for( int c = 0; c < source.Columns.Count; c++ )
dest.Rows[r][c] = source.Rows[c][r];


Ravindra Sadaphule
MCSD.NET

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.