William
Mon Apr 26 08:41:16 CDT 2004
1) DataReaders fill faster b/c DataADapter.Fill uses a datareader to fill
the datatable, so it's at least the same plus the overhead of building the
table. Depending on the size of the queyr, the difference can be
noticeable. Here's a test run where they did the comparison in multiple
scenarios
http://www.devx.com/vb2themax/Article/19887
2) Calling 2 queries, if I understand your questions correctly ,
ExecuteNonQuery + ExcecuteReader vs Da.Fill is almost certianly going to
take mroe effort. I'm not totally sure I understand the scenario though and
if I do, I don't see how it's apples to apples comparison with DataAdapters.
In general though, Output Parameters, as well as InputOutput params are more
efficient than returning whole rowssets or recordsets\
3) dr.GetInt32(0) is the fastest of the method. If you use a Name, then it
needs to be resolved at each pass for each column. This defintiely has some
overhead. There's a GetOrdinan Method of the datareader, but BIll Vaugn
proposes using an Enum instead b/c this will give you the readability of
using a named based lookup (which is what GetOrdinal does for you) without
incurring the overhead of calling getOrdinal(If you use getordinal, remember
to call it only once before your loop. If you call it each time within the
loop, it will actually be slowing b/c it will have to do a lookup just like
the other method does, but is slightly more expensive from what I've been
told. So only call GetOrdinal once for each field. But Vaughn's idea is
very clear, easy to use and the most efficient.. so instead of GetInt32(0)
YOu could ue GetInt32(MyNum.FirstField) where FirstField is the 0th piece fo
the enum.
As you can tell, dr[FieldName] is the second slowest of the method and dr[0]
(I didn't even think that would compile in C#. or in VB.NET with Option
Strict On).
That is the worst possible way. It's not clear what you are trying to do,
uses implicit type conversion and is just ugly.
"B0nj" <anonymous@discussions.microsoft.com> wrote in message
news:4867C257-DE3F-40B1-A66C-981CAC0729F0@microsoft.com...
> Could someone tell me which is faster, or no difference, between:
>
> Which is the fastest out of the following two methods???
> Reading a recordset using SqlDataAdapter.Fill(a_dataset) / reading a
recordset using SqlDataReader ??
>
> Which is the fastest out of the following two methods???
> Reading a recordset using SqlDataAdapter.Fill(a_dataset) / reading a
recordset using SqlDataReader *after* doing an ExecuteNonQuery on the same
command (after changing an in parameter's value to enable the SQL to be
optimized) in to glean output parameters (which need to be used during the
reading of the records)
>
> Which of the following three is faster, or none at all???
> Accessing fields using dr.GetInt32(0) / dr["fieldname"] / or dr[0] ??