Search code examples
c#ado.netadorecordsetvb6-migration

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.


Solution

  • 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.