Re: Some newbie questions
- From: "W.G. Ryan - MVP" <WilliamRyan@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Oct 2005 16:17:22 -0400
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:u5YO%23SW2FHA.3492@xxxxxxxxxxxxxxxxxxxxxxx
> Bill,
>
> We are talking in my idea about columns. Rows as the OP ask, you can only
> get by index or by a find (where I see a rowfilter, a select or whatever
> than as the same). (or I miss something).
--Depends. You can get them using foreach syntax as well.
In this example though, the question was between referring to to value via
Table.Rows[WhateverIndex][ColumnIndexOrName] or looking for the ID value
which is just like any other value that was returned from the db. If
you're saying that referencing it via index is the fastest, then I agree
totally.
In a discussion about the typed
> and the untyped dataset. (As you know do I not see any difference than
> that a strongly typed dataset is inherited from the DataSet). with Jay B.
> I thought me to remember that he told me that he had read something in
> Davids book. I don't have Davids book.
-- Performance is notably different. While it's true that typed datasets
inherit from DataSet, DataSets inherit from Object if you go far enough up
the chain. I suspect it's for similar reasons that Strongly Typed
collections are quicker than non typed collections. When you iterate
through each element, there isn't the same amount of checking that needs to
be done internally [this is just a guess but I think it's a pretty safe
assumption). The performance differences between the two are notable in
absolute terms, but they both happen so fast that from a human's point of
view, the difference is negligible. I'm not sure I follow you though about
Jay, is he saying that he's seen better performance with typed or untyped
datasets.
>
> There are 6 overloaded methods to index an item in a datarow. In fact that
> are 3 because the rest is filtering the rowstatus.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatarowclassitemtopic.asp
>
> To my suprise was the datacolumn indexer the fastest. Looking deeper in
> it, I thought me to remember, was it because the indexer gets the
> information from the datacolumn before he takes the item. The string was
> faremost the slowest, I thought because it was first searching the
> columname.
--I'd expect the string to be the slowest but the indexer part is what's
curious. In VB.nET for instance, the second one is faster which intuitively
is what you'd expect. But in C#, the first one is faster (yes, it's hard to
believe but if you check the IL, it is)
Dim TestTable As New DataTable("MyTable")
For i As Int32 = 0 To TestTable.Rows.Count
Debug.WriteLine(i.ToString())
Next
Dim x As Int32 = TestTable.Rows.Count
For z As Int32 = 0 To x
Debug.WriteLine(x.ToString) ' This is faster in VB.NET as you'd expect,
but in C# it's slower
Next
The same holds for columns so what's really 'faster' depends on many factors
and what's true in C# may not be the same for VB.NET and vice versa.
But in respect to the Columnindex, the index is faster b/c it doesn't have
to perform string lookups each time.
Next
>
> I hope this explains it more.
>
> Cor
>
.
- References:
- Re: Some newbie questions
- From: W.G. Ryan - MVP
- Re: Some newbie questions
- From: Cor Ligthert [MVP]
- Re: Some newbie questions
- From: W.G. Ryan - MVP
- Re: Some newbie questions
- Prev by Date: Re: Adding deleted rows back to a DataTable
- Next by Date: Re: Newbie with a Problem
- Previous by thread: Re: Some newbie questions
- Next by thread: Where namespace have ObjectSpace?
- Index(es):
Relevant Pages
|