W
William Ryan eMVP
Tiraman:
Depending on the functionality you need, a datareader may be more costly
over the session. It's certainly faster in a head to head comparison, but
if you need functionaility like Paging and sorting on a datagrid, you'll
probably be better off with a DataTable b/c youl'll have to keep going back
to the db for your data if you use a Reader.
I would highly discourage ever taking an approach that cuts off alternatives
wihthout waying the costs and benefits. There may be other reasons for
avoiding datasets, but simply b/c you think that datareaders are more
efficient isn't one of them.
It really depends on your web site needs. If you have lots of grids and
lists and comboboxes that share the same data and/or need sorting,
datatables are the way to go for most of that. Use cmd.ExecuteScalar for
instance to get back individual values. Use Stored procedures if possible.
Use Output Paramaters to get values back instaed of whole record sets.
You can use DataTable.Rows.Count to get the number of rows returned by a
datatable. You can use an integer to get the records affected by an
ExecuteNonQuery.
For a datareader, if you are using the 1.1 framework, you can use the
..HasRows property to determine if you have rows or not, but you'll have to
go through the reader to get the number of rows in there.
If you have any questions though, please feel free to ask.
Cheers,
Bill
Depending on the functionality you need, a datareader may be more costly
over the session. It's certainly faster in a head to head comparison, but
if you need functionaility like Paging and sorting on a datagrid, you'll
probably be better off with a DataTable b/c youl'll have to keep going back
to the db for your data if you use a Reader.
I would highly discourage ever taking an approach that cuts off alternatives
wihthout waying the costs and benefits. There may be other reasons for
avoiding datasets, but simply b/c you think that datareaders are more
efficient isn't one of them.
It really depends on your web site needs. If you have lots of grids and
lists and comboboxes that share the same data and/or need sorting,
datatables are the way to go for most of that. Use cmd.ExecuteScalar for
instance to get back individual values. Use Stored procedures if possible.
Use Output Paramaters to get values back instaed of whole record sets.
You can use DataTable.Rows.Count to get the number of rows returned by a
datatable. You can use an integer to get the records affected by an
ExecuteNonQuery.
For a datareader, if you are using the 1.1 framework, you can use the
..HasRows property to determine if you have rows or not, but you'll have to
go through the reader to get the number of rows in there.
If you have any questions though, please feel free to ask.
Cheers,
Bill