Q

Converting VB6 adodb.recordset to VB.NET

I used adodb.recordset for my VB6 projects. Now, I would like to convert it into VB.NET and use the recordset again. My question is, how do I convert the following code:
dim rsCust as recordset dim abc as string abc = rsCust!salesprice
The VB6 "bang" operator provides condensed syntax for indicating fields within a recordset. In VB.NET the "bang" syntax is no longer supported.

The answer to your question is different depending upon whether Option Strict is On or Off. By default it is Off and VB.NET will do implicit conversions between datatypes.

For Option Strict Off the short answer is:

abc = rsCust("salesprice").Value

For Option Strict On explicit type conversion is required and for string fields the ToString method of the value performs the conversion:

abc = rsCust("salesprice").Value.ToString

However, if you are not tied to the ADO recordset, I suggest spending the time to upgrade to ADO.NET where you can use Strongly Typed DataSets. The field names are verified by Visual Studios Intellisense and the new syntax is almost the same as the VB6 syntax:

abc = rowCust.saleprice

There are many good articles on using ADO.NET and Strongly Typed DataSets available in the Microsoft documentation.

This was first published in July 2004

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close