dataset and sort

S

Sehboo

I call a stored procedure and get the data in dataset then I do this
to sort my data
myDS.Tables[0].Select("" , "terminal DESC");

but it doesn't sort. If I put something in filter then it totally
ignors that as well...am I missing something?
 
S

sloan

You gotta set a variable to the results


DataRow [] rows = ds.Tables[0].Select("" , "terminal DESC");

then loop on the rows, cast them if necessary (for a strongly typed dataset)
 
N

Nicholas Paldino [.NET/C# MVP]

Sehboo,

Instead of calling Select, you should use a DataView and set the Sort
property to "terminal DESC".
 
S

Sehboo

I tried this as well
myDS.Tables[0].DefaultView.Sort = "terminal DESC";

but it ignores it too. It always shows the data in the order which
was returned by stored procedure. I am trying to overwrite it.

Sehboo,

Instead of calling Select, you should use a DataView and set the Sort
property to "terminal DESC".

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I call a stored procedure and get the data in dataset then I do this
to sort my data
myDS.Tables[0].Select("" , "terminal DESC");
but it doesn't sort. If I put something in filter then it totally
ignors that as well...am I missing something?- Hide quoted text -

- Show quoted text -
 
N

Nicholas Paldino [.NET/C# MVP]

Sehboo,

This is what a DataView is for. You shouldn't use the DefaultView
property, but create a new DataView.

The reason it doesn't work when setting the property on the DefaultView
is because you have to access the DefaultView, not the DataSet to get the
sorted results. Manipulating the DefaultView is usually not a good idea.

Basically, create a new instance of the DataView class and pass that
around after you set the sort, and work with that.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Sehboo said:
I tried this as well
myDS.Tables[0].DefaultView.Sort = "terminal DESC";

but it ignores it too. It always shows the data in the order which
was returned by stored procedure. I am trying to overwrite it.

Sehboo,

Instead of calling Select, you should use a DataView and set the Sort
property to "terminal DESC".

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I call a stored procedure and get the data in dataset then I do this
to sort my data
myDS.Tables[0].Select("" , "terminal DESC");
but it doesn't sort. If I put something in filter then it totally
ignors that as well...am I missing something?- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top