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.
Dig Deeper on VB 6 to VB .NET Migration
Related Q&A from Samuel Matzen
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.