473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sort DataTable -C#


private DataTable SortDataTable(D ataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Cl one();
int rowCount = GetDataTable.Ro ws.Count;

DataRow[] foundRows = GetDataTable.Se lect(null, sort);
// Sort with Column name
for (int i = 0; i < rowCount; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = foundRows[i][j];
}
DataRow data_row = _NewDataTable.N ewRow();
data_row.ItemAr ray = arr;
_NewDataTable.R ows.Add(data_ro w);
}

//Clear the incoming GetDataTable
GetDataTable.Ro ws.Clear();

for (int i = 0; i < _NewDataTable.R ows.Count; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = _NewDataTable.R ows[i][j];
}

DataRow data_row = GetDataTable.Ne wRow();
data_row.ItemAr ray = arr;
GetDataTable.Ro ws.Add(data_row );
}
return _NewDataTable;
}


Jun 27 '08 #1
3 5008
what the hell you are trying to do here??

Nirosh

<Bimal Kothariwrote in message
news:20******** *************** *@yahoo.com...
>
private DataTable SortDataTable(D ataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Cl one();
int rowCount = GetDataTable.Ro ws.Count;

DataRow[] foundRows = GetDataTable.Se lect(null, sort);
// Sort with Column name
for (int i = 0; i < rowCount; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = foundRows[i][j];
}
DataRow data_row = _NewDataTable.N ewRow();
data_row.ItemAr ray = arr;
_NewDataTable.R ows.Add(data_ro w);
}

//Clear the incoming GetDataTable
GetDataTable.Ro ws.Clear();

for (int i = 0; i < _NewDataTable.R ows.Count; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = _NewDataTable.R ows[i][j];
}

DataRow data_row = GetDataTable.Ne wRow();
data_row.ItemAr ray = arr;
GetDataTable.Ro ws.Add(data_row );
}
return _NewDataTable;
}


Jun 27 '08 #2
Nirosh wrote:
what the hell you are trying to do here??
Sort a DataTable?

Nirosh

<Bimal Kothariwrote in message
news:20******** *************** *@yahoo.com...
>private DataTable SortDataTable(D ataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Cl one();
int rowCount = GetDataTable.Ro ws.Count;

DataRow[] foundRows = GetDataTable.Se lect(null, sort);
// Sort with Column name
for (int i = 0; i < rowCount; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = foundRows[i][j];
}
DataRow data_row = _NewDataTable.N ewRow();
data_row.ItemAr ray = arr;
_NewDataTable.R ows.Add(data_ro w);
}

//Clear the incoming GetDataTable
GetDataTable.Ro ws.Clear();

for (int i = 0; i < _NewDataTable.R ows.Count; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = _NewDataTable.R ows[i][j];
}

DataRow data_row = GetDataTable.Ne wRow();
data_row.ItemAr ray = arr;
GetDataTable.Ro ws.Add(data_row );
}
return _NewDataTable;
}


Jun 27 '08 #3
Hello Just pass your data table and sort expression to sort (Date
and Amount) columns

Ok

"Andrew Cooper" wrote:
Nirosh wrote:
what the hell you are trying to do here??

Sort a DataTable?

Nirosh

<Bimal Kothariwrote in message
news:20******** *************** *@yahoo.com...
private DataTable SortDataTable(D ataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Cl one();
int rowCount = GetDataTable.Ro ws.Count;

DataRow[] foundRows = GetDataTable.Se lect(null, sort);
// Sort with Column name
for (int i = 0; i < rowCount; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = foundRows[i][j];
}
DataRow data_row = _NewDataTable.N ewRow();
data_row.ItemAr ray = arr;
_NewDataTable.R ows.Add(data_ro w);
}

//Clear the incoming GetDataTable
GetDataTable.Ro ws.Clear();

for (int i = 0; i < _NewDataTable.R ows.Count; i++)
{
object[] arr = new object[GetDataTable.Co lumns.Count];
for (int j = 0; j < GetDataTable.Co lumns.Count; j++)
{
arr[j] = _NewDataTable.R ows[i][j];
}

DataRow data_row = GetDataTable.Ne wRow();
data_row.ItemAr ray = arr;
GetDataTable.Ro ws.Add(data_row );
}
return _NewDataTable;
}

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
587
by: ETX | last post by:
Hello, My question is about the datagrid sorting. I have a datatable that is filled up with the data retrieved from an SQL query.I use that datatable as source for my datagrid. I would like to make the datagrid sortable by each of the columns but I don´t want to run the SQL query again. The problem is that I'm loosing the datatable every time the sorting function is launched. I'm not allowed to use session variables and I don't know how...
6
9292
by: Hardy Wang | last post by:
Hi, I have a DataSet, returned by a stored procudure, which has only on DataTable. At this step there is no sort in DataTable. Is there is a way I can do to sort DataRows in this DataTable (not from select statement of sql query) in memory? Thanks -- WWW: http://hardywang.1accesshost.com ICQ: 3359839
2
3181
by: Fredrik Rodin | last post by:
All, I've been looking around for a solution to my problem for a couple of days now. In short, here's my situation: 1. I'm getting a result from a component back as a datatable and I have no option to sort the different columns during the call to the component.
1
1776
by: troyblakely | last post by:
I am having trouble sorting a datagrid. I have read numerous posts on this and other lists, and tried most of the suggestions, but none of them have worked for me yet. I populate a dataset from two queries, then I want to sort the data and bind it to a datagrid. Regardless of what I have tried, the datagrid is populated with the unsorted data. Any assistance you have would be appreciated. I have attempted the sort using the dataview.sort...
5
2234
by: Gene Hubert | last post by:
I'm using the DefaultView from the Datasource for a DataGrid to present the data in a particular order. It seems that sorting in this way is an "Active Sort", as is the default sort that is provided by clicking on a column header. By "Active Sort", I mean that editing a value in a sorted column may cause the record to be moved to maintain the sort order. Is there an efficient way to present the data in a given order but not have it be...
1
1990
by: Lyners | last post by:
I am trying to figure out the best way to do this (currently I am having a problem sorting). I have a vb.net program that contains 2 datagrids on a form for the end user. When the user is ready to process, behind the scenes, I combine the 2 datagridas into a datatable, sort and do processing for creating a load into another system. My problem is that when I combine the two datagrids into the 1 datatable, I can only sort in a dataview. When...
3
4498
by: gilly3 | last post by:
I have a column in a DataView that contains NaN. When I attempt to Sort on this column, I get: MESSAGE: Index was outside the bounds of the array. SOURCE: System.Data STACKTRACE: at System.Data.Index.Sort(Int32 left, Int32 right) at System.Data.Index.InitRecords() at System.Data.Index..ctor(DataTable table, Int32 indexDesc, DataViewRowState recordStates, IFilter rowFilter)
3
1877
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Are there any good built-in or availble functions that I can call to sort my dataset datatalbe based on 1 or more of the table's columns? -- Thanks.
4
1703
by: sklett | last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I thought I would post here as well. I hope no one minds too much, if you do I'm sorry) I have a DGV that is bound to a DataTable that is loaded during application startup. I can sort with all the columns and everything works fine. I have a method that can be invoked from a context menu that will loop through the rows of the bound table and modify a specific cell in...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.