Datatable.Select or DataView

  • Thread starter Thread starter Zaczyk, Joe
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top