Chris Pfohl
Chris Pfohl

Reputation: 19064

Ado.Net RecordSet member equivalent?

I'm currently re-writing a Vb6 program relying on ADO into C# w/ ADO.NET. I've run into several places in the original code with stuff like this:

Dim rs As New Recordset
rs.CacheSize = 500
Call rs.Open(sSql, cnMeta, adOpenForwardOnly, adLockReadOnly)

Is there an equivalent (or even a need for an equivalent) to ADO.RecordSet.CacheSize in Ado.Net? (Capitalization on those?) I'm happy to accept "ADO.NET" takes care of that for you (very happy to accept that, in fact). My problem is that that I had no ADO experience before this migration so I'm not sure if there's subtleties I'd be missing.

Do I understand correctly that adOpenForwardOnly and adLockReadOnly are the [EDIT] way to make RecordSet behave like SqlDataReader already does [/EDIT]? If so, then my only real question is whether or not I need to make Ado.Net cache more or if that gets handled by default.

I'm really sorry if this is a repeated question. I can't seem to find this on S.O. or msdn though.

Upvotes: 2

Views: 2010

Answers (2)

Keith
Keith

Reputation: 5381

This post may help:

http://www.devnewsgroups.net/adonet/t55360-paging-recordsets-ado-net.aspx

Also a quick link to the MSDN CacheSize topic:

http://msdn.microsoft.com/en-us/library/ms675871%28VS.85%29.aspx

My recommendation, however, would be to familiarize yourself with Linq-to-SQL, which was introduced in .NET 3.5. I'd rather not help recommend you to replace outdated VB6 functionality with ADO.NET, when I have had great experiences with LINQ (which is built on ADO.NET and is very programmer-friendly) - read here, among many places, to see what the differences are.

Upvotes: 1

Guffa
Guffa

Reputation: 700362

The CacheSize property controls how many records the recordset reads into it's internal buffer. There is no equivalent property in ADO.NET, because it's not buffered in the same way. So, you can just leave that out.

Do I understand correctly that adOpenForwardOnly and adLockReadOnly are the defaults for SqlDataReader?

Yes. Well, it's not the default, but rather the only way that the data reader ever works. For any other way that a RecordSet is used, you would use other classes, like DataSet and SqlDataAdapter.

Upvotes: 2

Related Questions