views:

34

answers:

2

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.

+1  A: 

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.

Keith
Thanks, that's helpful. It looks like I can pretty much pretend the code wasn't there and make it more efficient in more .Net-ey ways.
Cpfohl
See my edits - I added that I should also recommend LINQ-To-SQL versus ADO.NET
Keith
Thanks for the advice. I've used (and loved) some Linq-to-Sql, but unfortunately it doesn't fit in my particular case. I use queries that select from arbitrary tables depending on the contents of another database (with a more stable schema). I could use half-and-half Linq-to-Sql/ADO.Net, but it seemed better to be consistent.
Cpfohl
+1  A: 

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.

Guffa
Even better. Thanks, your explanation answers more of my questions, more directly.
Cpfohl