473,943 Members | 15,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet sorting

Hi List

I´m generating a DataSet using a simple sql select statement. Now my DataSet
has several rows with columns(ID,NAME ,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order
by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultD S.Tables[0].DefaultView;//new
DataView(this.s qlResultDS.Tabl es[0]);
sortView.AllowE dit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does not
function)

----------------------------------------------------------------------------
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn
Nov 18 '05 #1
3 5354
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data
this line removes the table...

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does not
function)
this line again tries to add the same table.. when you sort using sortview,
i dont think the underlying table gets modified. when you bind the DataView
to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx .net> wrote in message
news:Oe******** *****@TK2MSFTNG P12.phx.gbl...
Hi List

I´m generating a DataSet using a simple sql select statement. Now my
DataSet
has several rows with columns(ID,NAME ,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order
by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultD S.Tables[0].DefaultView;//new
DataView(this.s qlResultDS.Tabl es[0]);
sortView.AllowE dit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does
not
function)

----------------------------------------------------------------------------
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn

Nov 18 '05 #2
Hey

Thanks for your answer.
Because I´m working with dataset in a class project and not a web project I
can´t bind the DataView to an Aspnet Control.
So this means I have to implement the sort for the dataset on my own? right?

regards

Björn

"avnrao" <av*@newsgroups .com> schrieb im Newsbeitrag
news:#0******** ******@TK2MSFTN GP12.phx.gbl...
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data
this line removes the table...

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does not function)
this line again tries to add the same table.. when you sort using sortview, i dont think the underlying table gets modified. when you bind the DataView to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx .net> wrote in message
news:Oe******** *****@TK2MSFTNG P12.phx.gbl...
Hi List

I´m generating a DataSet using a simple sql select statement. Now my
DataSet
has several rows with columns(ID,NAME ,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultD S.Tables[0].DefaultView;//new
DataView(this.s qlResultDS.Tabl es[0]);
sortView.AllowE dit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does
not
function)


--------------------------------------------------------------------------

--
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn


Nov 18 '05 #3
if you have to sort the values and just use them in the class as sorted, use
this code..

DataView sorted = GetDataView();
System.Collecti ons.IEnumerator ienum = sorted.GetEnume rator();
int iLen = sorted.Table.Ro ws.Count;
DataRowView drv;
while(ienum.Mov eNext())
{
drv = (DataRowView)ie num.Current;
lstBox.Items.Ad d(new ListItem(drv.Ro w["ProgramNam e"].ToString())); i
just added the value in the list box.
}

hth,
Av.
"Björn" <pr********@gmx .net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hey

Thanks for your answer.
Because I´m working with dataset in a class project and not a web project
I
can´t bind the DataView to an Aspnet Control.
So this means I have to implement the sort for the dataset on my own?
right?

regards

Björn

"avnrao" <av*@newsgroups .com> schrieb im Newsbeitrag
news:#0******** ******@TK2MSFTN GP12.phx.gbl...
this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data
this line removes the table...

this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does

not
function)
this line again tries to add the same table.. when you sort using

sortview,
i dont think the underlying table gets modified. when you bind the

DataView
to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx .net> wrote in message
news:Oe******** *****@TK2MSFTNG P12.phx.gbl...
> Hi List
>
> I´m generating a DataSet using a simple sql select statement. Now my
> DataSet
> has several rows with columns(ID,NAME ,CAPTION)
>
> Now I want to sort the DataSet for column Caption. I can´t use sql "order > by" because the caption field is of Sqltype text.
> So I wanted to use the DataView object sort order.
> ----sample code--------------------------
> DataView sortView = this.sqlResultD S.Tables[0].DefaultView;//new
> DataView(this.s qlResultDS.Tabl es[0]);
> sortView.AllowE dit = true;
>
> sortView.Sort = "CAPTION DESC";//sort data
>
>
> this.sqlResultD S.Tables.Remove At(0);//remove old unsorted data
>
> this.sqlResultD S.Tables.Add(so rtView.Table);//add new sorted data (does
> not
> function)
>


--------------------------------------------------------------------------

--
> ----------------
>
> Something is wrong with my Code, the data is not sorted.
>
> Any ideas???
>
> regards
>
>
>
> Björn
>
>



Nov 18 '05 #4

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

Similar topics

11
16403
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so applications that see the results as xml don't have to fiddle around and sort it themselves later). I have tried sorting a dataview and adding that dataview's table to the dataset but the results don't remain sorted. The only way I can see to do...
4
441
by: Deepa | last post by:
I have a dataset which am trying to sort by 3 specific columns. I am not making any connection to the database to get the dataset. I have the raw dataset already. What i tried doing was to create a DataView and sort it by a column name. mydataset.ReadXml(@sResponseXML); DataView mydataview = new DataView(); mydataview = ds.Tables.DefaultView; mydataview.Sort = "ColumnName";
4
10052
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't have a .getxml method (unlike the dataset). any ideas? thanks.
2
1443
by: Aric Levin | last post by:
I have a Dataset that I read from SQL Server. The dataset can contain more items that I want to display. When I try to resort the dataset it doesn't sort. Here is the Syntax. I am not sure what the problem is: DataSet oDS = (DataSet)Cache; Sort = Session; // Removes All Sorting Signs
4
1601
by: rodchar | last post by:
hey all, Regarding paging and sorting in a datagrid, is it better to: A: persist a dataset in session or B:
2
3712
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than the database. This would not be a problem, and really isn't a problem except that it means I have to search the dataset each time I want to find a particular record instead of just storing a variable. Which brings me to a different question....
3
2780
by: Freeon | last post by:
Hi, I am looking for a way to sort a strong typed dataset. It would seem the most straightforward way is to use a dataview. The only problem is when I use the dataview I seem to loose the strong typed properties from my original dataset Anyone that can point me to an example of how to sort my dataset and maintain the use of my typed properties would be greatly appreciated Thank, Freeon
7
8753
by: Brett Romero | last post by:
I have a dataset with one table, which has four columns. All are of type INT. I need to convert this dataset into a dataview so I can sort on the last three columns. I may sort one of the three or all three at once. This dataview will display its results in a winform datagrid. Right now, I create the dataset from a datareader: while(dr.Read()) { drow = _filteredCriteriaDataSet.Tables.NewRow();
6
16753
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to return the DataSet type when using the following code: ======== this is my interface ====================== namespace WareHouse.DataLayer.DataObjects { /// <summary> /// Defines methods to access categories and products.
0
11539
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11133
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
11303
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
10666
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
8228
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
7393
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6090
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...
0
6312
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3516
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.