PC Review


Reply
Thread Tools Rate Thread

Dataview sort method is not sorting ....

 
 
Sarah Smith
Guest
Posts: n/a
 
      19th Feb 2004

hello,

I am using the DataView object to sort records from a dataset.

I use this code to read from the dataview to 2 text boxes on screen:

Me.txtName.Text = myDataView.Table.Rows(nRecord).Item(0).ToString

Me.txtTEL.Text = myDataView.Table.Rows(nRecord).Item(1).ToString



nRecord is updated by navigation buttons. The columns referenced in
Item(0) and Item(1) are "Name" and "Tel"

After creating the DataView, I sort the data using myDataView.Sort =
"Name ASC" or myDataView.Sort = "Name, Tel ASC"

When I use the navigation buttons, the records still appear in the
same order that they were added to the underlying DataSet. (Not
sorted).

But .... if I attach a Data grid to the DataView, then the records
appear sorted and correct.

I've also tried like this:
Me.txtName.Text =
myDataView.Table.DefaultView.Item(nRecord).Row.Item(0).ToString()
Me.txtTEL.Text =
myDataView.Table.DefaultView.Item(nRecord).Row.Item(1).ToString()


Can anyone see something obvious I'm doing wrong?

SS.



 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      19th Feb 2004
It appears you are binding to the underlying table, not the dataview itself,
therefore navigation between the rows will of course be in the order of the
table (not the view).

Try this instead:-
Me.txtName.Text = myDataView(nRecord).Item(0).ToString()

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Sarah Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> hello,
>
> I am using the DataView object to sort records from a dataset.
>
> I use this code to read from the dataview to 2 text boxes on screen:
>
> Me.txtName.Text = myDataView.Table.Rows(nRecord).Item(0).ToString
>
> Me.txtTEL.Text = myDataView.Table.Rows(nRecord).Item(1).ToString
>
>
>
> nRecord is updated by navigation buttons. The columns referenced in
> Item(0) and Item(1) are "Name" and "Tel"
>
> After creating the DataView, I sort the data using myDataView.Sort =
> "Name ASC" or myDataView.Sort = "Name, Tel ASC"
>
> When I use the navigation buttons, the records still appear in the
> same order that they were added to the underlying DataSet. (Not
> sorted).
>
> But .... if I attach a Data grid to the DataView, then the records
> appear sorted and correct.
>
> I've also tried like this:
> Me.txtName.Text =
> myDataView.Table.DefaultView.Item(nRecord).Row.Item(0).ToString()
> Me.txtTEL.Text =
> myDataView.Table.DefaultView.Item(nRecord).Row.Item(1).ToString()
>
>
> Can anyone see something obvious I'm doing wrong?
>
> SS.
>
>
>



 
Reply With Quote
 
Sarah Smith
Guest
Posts: n/a
 
      19th Feb 2004

Thanks a lot Peter, that did the trick, but I had to change it to
named columns like this:

Me.txtTEL.Text = myDataView(nRecord).Item("Tel").ToString

..... because I have Option Strict turned on.

Do you think it will make a difference in performance if I turn off
Option Strict and used indexing instead?

Thanks,

SS.



On Thu, 19 Feb 2004 13:10:42 -0000, "Peter Foot [MVP]"
<(E-Mail Removed)> wrote:

>It appears you are binding to the underlying table, not the dataview itself,
>therefore navigation between the rows will of course be in the order of the
>table (not the view).
>
>Try this instead:-
>Me.txtName.Text = myDataView(nRecord).Item(0).ToString()
>
>Peter


 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      19th Feb 2004
Sarah:

In general you'll want to use Index based lookups for performance, however,
this only affects code where you are using the dataview/datatable and with
small numbers of records, the performance difference is very small.
However, Option Strict should be left on b/c if you turn it off, you'll
probably start injecting implicit type conversions and Options Slow will be
on. I'd go ahead and just use the String based lookup on this and leave
Option Strict on.

HTH,

Bill
"Sarah Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Thanks a lot Peter, that did the trick, but I had to change it to
> named columns like this:
>
> Me.txtTEL.Text = myDataView(nRecord).Item("Tel").ToString
>
> .... because I have Option Strict turned on.
>
> Do you think it will make a difference in performance if I turn off
> Option Strict and used indexing instead?
>
> Thanks,
>
> SS.
>
>
>
> On Thu, 19 Feb 2004 13:10:42 -0000, "Peter Foot [MVP]"
> <(E-Mail Removed)> wrote:
>
> >It appears you are binding to the underlying table, not the dataview

itself,
> >therefore navigation between the rows will of course be in the order of

the
> >table (not the view).
> >
> >Try this instead:-
> >Me.txtName.Text = myDataView(nRecord).Item(0).ToString()
> >
> >Peter

>



 
Reply With Quote
 
Sarah Smith
Guest
Posts: n/a
 
      19th Feb 2004

Will do. Thanks for the advice.

SS.


On Thu, 19 Feb 2004 10:48:43 -0500, "William Ryan eMVP"
<(E-Mail Removed)> wrote:

>Sarah:
>
>In general you'll want to use Index based lookups for performance, however,
>this only affects code where you are using the dataview/datatable and with
>small numbers of records, the performance difference is very small.
>However, Option Strict should be left on b/c if you turn it off, you'll
>probably start injecting implicit type conversions and Options Slow will be
>on. I'd go ahead and just use the String based lookup on this and leave
>Option Strict on.
>
>HTH,
>
>Bill
>"Sarah Smith" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>
>> Thanks a lot Peter, that did the trick, but I had to change it to
>> named columns like this:
>>
>> Me.txtTEL.Text = myDataView(nRecord).Item("Tel").ToString
>>
>> .... because I have Option Strict turned on.
>>
>> Do you think it will make a difference in performance if I turn off
>> Option Strict and used indexing instead?
>>
>> Thanks,
>>
>> SS.
>>
>>
>>
>> On Thu, 19 Feb 2004 13:10:42 -0000, "Peter Foot [MVP]"
>> <(E-Mail Removed)> wrote:
>>
>> >It appears you are binding to the underlying table, not the dataview

>itself,
>> >therefore navigation between the rows will of course be in the order of

>the
>> >table (not the view).
>> >
>> >Try this instead:-
>> >Me.txtName.Text = myDataView(nRecord).Item(0).ToString()
>> >
>> >Peter

>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does the DataView.Sort method really work under the covers? anon Microsoft Dot NET 1 14th May 2004 04:48 PM
How does the DataView.Sort method really work under the covers? anon Microsoft ADO .NET 1 14th May 2004 04:48 PM
How does the DataView.Sort method really work under the covers? anon Microsoft Dot NET Framework 1 14th May 2004 04:48 PM
DataView.Sort not sorting Microsoft ADO .NET 2 25th Oct 2003 09:39 PM
How to use Find method in dataview for multiple column sort? ittemp Microsoft ADO .NET 1 31st Jul 2003 07:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:24 PM.