querying columns from tables

  • Thread starter Thread starter C# newcomer
  • Start date Start date
C

C# newcomer

Hi all
If I have to read just one or two columns from my SQL
server table, is data reader the only option? or is there
a more efficient way?
Thanks a lot in advance for your replies.
 
It depends on what you want to do. A DataReader is a very fast way to read
data, but the tradeoff is functionality. DataReaders only work when there's
an open DB connection and they are forward only /read only. If efficiency
is the only concern, then DataReaders are probably what you need. But using
a DataAdapter/Dataset and disconnected objects are probably something you'll
want to use in the majority of your apps.

It's a right tool for the right job. While a Concord might be a very fast
transport mechanism, it's a bit much as a vehicle to get to work in. On the
other hand, an 18 Wheeler can do many things for you functionally, but there
are times you don't need all of that functionality so it's overkill. These
analogies are a bit extreme, but the point is that things are often more
like Tradeoffs than either/ors. And there's no universal answer for things
like this..what make be a great solution in one app is terrible in another.
What was a great solution when you had 20000 records might be terrible when
you have 50000000.

If you are new to ADO.NET, you'll probably want to pick up David Sceppa's
ADO.NET Core Reference, Bill Vaughn's Best Practices http://www.betav.com/
And if at all possible both of them. You may also want to check out the
DAAB which is Microsoft's Best Practices for Data Access.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/
daab-rm.asp
 
You can use the datareader regardless of how many columns you want to read.
Just make sure the stored procedure or sql statement only selects the
columns you need.


Arild
 
Back
Top