Datatable.Select or DataView

Z

Zaczyk, Joe

I want to kow which one is faster out of these two examples. (Select or
Dataview)

This is just an example.

Dim FilterCondition As String = ""
Dim Dt As DataTable
dt = da.Fill(dt) 'Query=Select EmpID, EmpName, ReportingTo from EMP
Dim row As DataRow
Dim rowEmp As DataRow

Example 1
===========
For Each rowEmp In dt.Rows
FilterCondition = "ReportingTo=" & rowEmp("EmpID")
If dt.Select(FilterCondition).Length > 0 Then
For Each row In dt.Select(FilterCondition)
'TODO
Next
End If
Next

Example 2
=========
For Each rowEmp In dt.Rows
FilterCondition = "ReportingTo=" & rowEmp("EmpID")
Dim dv As DataView = New DataView(dt, FilterCondition, "",
DataViewRowState.OriginalRows)
If dv.Count > 0 Then
For Each row In dv
'TODO
Next
End If
Next


Again, This is just an example to explain my question.
Thanks,
Joe
 
C

Cor Ligthert [MVP]

Joe,

This kind of things are easy to test. When you look in the message thread
from yesterday started by DraguVaso. "Fasts way to merge 2
DataTables/Dataview/..." then you see how test that.

Don't expect to much from this. If a user moves his 'form' 1 pixel aside
than there will probably 100000 times more time be consume than with
calibrating the actions that you are doing now.

However it can always be interesting to know what it can be.

Cor
 
Z

Zaczyk, Joe

Thanks Malik,
So DavaView is better then DataTable.Select.
I also want to know is your book(ADO.Net 2.0) already released and available
in Barns and Nobels as Framework is not yet released.

Joe
 
S

Sahil Malik [MVP]

DataView does have an overhead of being a whole another object - not a big
deal since most of it is just references to underlying datatable and
datarows. Yes in general dataview will be faster, but for the speediest
repeated performance, you probably want to setup a dummy datatable with
dummy datarelations - that would be the speediest solution in repeated
requests.

Yes the book is out and available :). And thanks Bill for your kind words.
:)

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
S

Sahil Malik [MVP]

Don't expect to much from this. If a user moves his 'form' 1 pixel aside
than there will probably 100000 times more time be consume than with
calibrating the actions that you are doing now.

Not necessarily. User actions are in the UI and such filtering may very well
be in the middle/data tier, which is running on a shared resource - where
performance is super critical.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 

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