.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to interchange columns to rows in datatable

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :.NET Framework
I have datatable with following structure

Column1 Column2 Column3 Column4





But I want to have data like this

Row1 Row2 Row3 Row4





How could we do this in ADO.net

View Complete Post

More Related Resource Links

MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

Adding Multiple Columns and Rows in GridView without using a Database

This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.

return only rows - no columns

Hi all, I'm using the below query to retrieve one vendor information. I dont want the columns and I need the query to return me one row with no column header. what would be the syntax for that. I'm trying to use this on SAP BW system - if that really matters. I tried tweaking the code, but SAP didnt seem to like it and the error message isnt helpful either. The code below works just fine - but I want to get rid of the column header SELECT [Measures].MEMBERS ON COLUMNS, NON EMPTY [0VENDOR].[LEVEL01].MEMBERS DIMENSION PROPERTIES [0VENDOR].[20VENDOR] ON ROWS FROM [OPOMCHS0/ZQT_GPO_PO_CHNG_REP_SUMM_3]WHERE[0VENDOR].[ABCD] Please help. Thanks in advance.

Find rows in one DataTable from another DataTable and remove them

Hi!I'm sure this is a ridiculously newbie question, but I'm having a lot of trouble with it and have spent hours wrestling and Googling this problem so I'm finally going to ask for help.I have a DataTable of available time slots.  I have another DataTable of reserved time slots.  I need to remove from the list of available slots the ones that have been reserved.  The blocks are in 15 minute increments, but one of my problems is that the reservation can be longer than 15 minutes.  I've had some luck removing one or two, but not all of the required columns.  Here's my code (it doesn't work right now).  Any help would be greatly appreciated!private void GetAvailableTime() { Common common = new Common(); DataTable copyAvailableTime = AvailableTime(); DataTable availableTime = AvailableTime(); DataTable reservedTime = ReservedTime(); StringBuilder sb = new StringBuilder(); copyAvailableTime.DefaultView.Sort = "startTime"; foreach (DataRow dr in reservedTime.Rows) { copyAvailableTime.DefaultView.RowFilter = string.Format("startTime >= '#{0}#' AND endTime <= #{1}#", dr["StartTime"].ToString(), dr["EndTime"].ToString()); foreach (DataRow dr2 i

Hiding rows/columns completely in SSRS tablix even when they have data

I have several columns and rows in my tablix.  I don't want to see all of them at once.  I am using a parameter that controls the visibility of the columns or rows of the tablix.  The issue is that it hides but the white space is left.  How do i take out that white space?

Converting rows to columns



I have the following temp table and I want insert each rows as columns in to another table


2007 1 1
2007 3 5

How do i convert rows to columns?


hi friends,

the fucntion splits the csv value : hello there, 1, 1  and returns as one column three row table

hello there



How do convert this table of one column and three rows in to 1 row and 3 columns?

then i need to insert that to a table @tmp with definiton declare @tmp (txt nvarchar(max), corr int, is_act int)



Converting Rows into Columns


I have the data stored in the table stored in the the following format

RuleNum          Condtion       CValue    Action      AValue

4.1                    STATE             TX           SA           0043
4.1                    STATE             NM           SA          0031
4.1                    STATE     &nbs

Using Cursors to bring one table's rows into another table's columns.



i have 2 tables; the first one records information about shapes. this table has 3 fields where the primary key is a composite one with the shapeID and DimensionName. 

one shape has 3 records in this table since there can only be 3 values as DimensionName for a given shape (weight, price and color)


the second table has the shape ID , weight, price and color as its columns. where the shapeID is the primary key.


now what i need to do is i need to map the first table's 3 columns in to 1 column of the second table. i am allowed to use cursors for this.


can anyone please explain how can a approach thisproblem?? code snippets are warmly welcomed. :)


please referr the image for further clarification. to view the image, click this link http://i53.tinypic.com/2rcal2x.png


thanks in advance


loop through different sets of rows in a datatable



I have a following scenario - 

A use selects criterias from a webform (C#) - a result is then returned from the sql. Say, to start, there are 2000 data returned from the sql and are stored in a dataset.

Now, the user wants to choose a number of drops (up to 6) - with the number of drops selected, they can enter their own quantity in each box. So, they can divide the 2000 records into 6 different drops. With each drop, there is campaigncode created based on the mail date and the job number they provide. 

So, now i have the 2000 records in a dataset. What i want to do is loop through the gridview where the user fill out the quantity depending on the number of drops (for ex: if they say 3 drops, then there will be 3 rows in gridview with 3 quantity box to fill).

In the loop, I am getting the quantity, dropdate and the job number. The Campaigncode is created as well. Then, i am looping through the datarow in the dataset; updating the Campaign Code column with the CampaignCode for the number of records thats set in a loop. It works but the Campaign Code is not populated for the next set of records.

Here is the code:

private void AddAEFiels()
        int _totalCount = 0;
        string job = null;
        foreach (GridViewRow row in gvDropDates.

Urgent:Create/Update Winforms grid columns and rows with config file values


I have legacy winforms datagrid , I have to add/replace columns with new values, My new column names and row values are changes as per new requirements , so I am looking to update datagrid form any config file , so in future for any new requirements , If I update my config file , it hast update existing datagrid.

Please suggest me the code; I am trying from 4 days and its urgent now.



Urgent:Create/Update Winforms grid columns and rows with config file values


I have legacy winforms datagrid , I have to add/replace columns with new values, My new column names and row values are changes as per new requirements , so I am looking to update datagrid form any config file , so in future for any new requirements , If I update my config file , it hast update existing datagrid.

Please suggest me the code; I am trying from 4 days and its urgent now.




columns and rows of grid generate dynamically



i am developing the applicaton, from which i have a grid and that grid i want to use for the insert data,

i have a page default.aspx page, in this i have a dropdownlist, according to selection of the dropdownlist, grid's cols and rows created dynamically in insert.aspx. so in page load of the insert.aspx the grid will automatically have that much of cols and rows and that all cell contain the textbox.

how can i set that dynamically....

please help me....

thanks in advance

waiting for the reply.....

Switch columns and rows in SSRS



I have a report with static columns that looks something like this:


Date                      Column 1             Column2                           Column30


Rows into Columns


Hi guys, Quick question on the best way to achieve the following:

Have have GL Balanaces as at End of month stored in a table.

 The columns i have are:   Year, Amount, Jan, Feb |To| Dec

Example values:

Year  Amount Jan Feb Mar Apr

2010 1500 100 250 150 300

 I would like to get the data out in a Year/Month Cumulitive Totals: Ie:

2010 Jan 1600 (Amount + Jan)

2010 Feb 1850 (Amount + Jan + Feb)

2010 Mar 2000 (Amount + Jan + Feb + Mar)

2010 Apr 2300 (Amount + Jan + Feb + Mar + Apr)

What is the best wayu to achieve this?? Im was thinking some sort of Case statement, but im not sure how to write it.. All advice would be great! Thanks Scotty

Scott Lancaster - Sys Admin

updating multiple rows for multiple columns of the table from other table



I have source table called customer. And data from this table is transfered to another database  with same table name.

that is database1(customer table) ----> database 2(customer table)

now in database 2, First time my program runs and it randomly get any name and ssn and then updates the first name, last name, ssn of all the customer_ID's in the customer table (I use RAND function)

Now second when i run the program, it recreates the name and ssn again but different, for the same customer_id.

So i want that once the particular customer_ID is updated, next time if i run the program. it shold not update the those updated customer id's

Thanks, Any help is appreciated.


Adding rows to a databound DataSet/DataTable from a ThreadPool thread does not update UI


I have an WPF .NET 4.0 application which creates a TreeView in the main thread, and databinds it to a DataSet which contains two DataTables. The datatables have a simple relationship between them which represents a two-level tree. When the treeview is initially drawn, it correctly displays all items from the two datatables as a two level tree.

When the DataTables are updated from the UI thread (add/delete/modify a row), the treeview is refreshed and the changes to the databound DataSet DataTables are visible in the treeview.

If changes to the DataTables are made from a ThreadPool thread, no exceptions are thrown, but the UI is not updated. I am using a threadpool thread because the changes will be initiated from multiple network devices and processing their data is fairly CPU intensive.

I am assuming that change notifications are not being propogated across threads for DataSets/DataTables.  Is this assumption correct? If so, are their recommended best practices to overcome this limitation?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend