473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reverse a Dataset

Hi there.

Anybody knows if is it possible to reverse a dataset? Lets say, if the
dataSet has 10 rows, row 1 will row 10 and row 10 will be 1 and so on...

Thanks in advance.

Paez
Dec 27 '06 #1
3 12315
"Paez" <marco.pais@[IGNORE]gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Anybody knows if is it possible to reverse a dataset? Lets say, if the
dataSet has 10 rows, row 1 will row 10 and row 10 will be 1 and so on...
I don't think there's anything built-in which would do this...

However, you could certainly walk through the rows in reverse order:

for (int intRow = MyDataSet.Tables[0].Rows.Count - 1; intRow >= 0; intRow--)
{
// do something with MyDataSet.Tables[0].Rows[intRow]
}
Dec 27 '06 #2
Hi Paez,

If you need to sort the DataRows just to display them on a DataGridView via
binding, for example, then just bind to a DataView instead and set the Sort
property. It's much easier and certainly more practical then reordering the
actual DataRows within the DataTable.

// dataTable is an instance of your DataTable
dataTable.DefaultView.Sort = "FirstName DESC";

dataGridView.DataSource = dataTable.DefaultView;

DataView Class
http://msdn2.microsoft.com/en-us/lib....dataview.aspx

You'll need a column to sort on, of course. If you simply need to reverse
the records as they exist in the DataTable then add a new AutoNumber column
to the DataTable and sort by that column.

Data Access in Client and Middle-Tier Programming
How to: Create an Autonumber DataColumn
http://msdn2.microsoft.com/en-gb/lib...4b(VS.80).aspx

--
Dave Sexton
http://davesexton.com/blog

"Paez" <marco.pais@[IGNORE]gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi there.

Anybody knows if is it possible to reverse a dataset? Lets say, if the
dataSet has 10 rows, row 1 will row 10 and row 10 will be 1 and so on...

Thanks in advance.

Paez


Dec 27 '06 #3
Hi,

Most probably you mean a DataTable, a dataset is mainly a set of Datatables
that are the one that contain the data.

There is nothing like that I'm afraid, the internal structure to hold the
DataRow is "unknow" how it store the elements.

What do you want to do anyway?

You can use a DataView and sort the rows in the order you want pretty
easily.
--
Ignacio Machin
machin AT laceupsolutions com

"Paez" <marco.pais@[IGNORE]gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi there.

Anybody knows if is it possible to reverse a dataset? Lets say, if the
dataSet has 10 rows, row 1 will row 10 and row 10 will be 1 and so on...

Thanks in advance.

Paez


Dec 27 '06 #4

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

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
8
by: Jim Langston | last post by:
I have a class I designed that stores text chat in a std::vector<sd::string>. This class has a few methods to retrieve these strings to be displayed on the screen. void ResetRead( bool Reverse,...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
19
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
1
by: PartyFears | last post by:
Dear All, I have the following problem. I have populated a datasset and bound the contents to varous text fields defined in a page. I do this through running Me.Databind in the Form_Load of...
20
by: mike7411 | last post by:
Is there any easy way to reverse the order of the bits in a byte in C++? (i.e. 00000001 becomes 10000000)
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.