- INDEX VB TO NET
- KNOWLEDGE BASE
- EWIS-WARNINGS
- WARNING #2077
WARNING #2077
Change the default 0 index in the Rows property with the correct one.
Description
When upgrading an ADO Recordset object to native ADO.Net, the VBUC converts all the Recordset objects to System.Data.DataSet, however there are major differences between these two classes.
Cursors are used in ADO control record navigation in a Recordset; this way you are always pointing to a current row in the Recordset. This concept is not available in a DataSet object, which contains a collection of tables, and each table contains a collection of Rows and Columns, among other data. Since there is no current row concept in a DataSet object, when there are uses of a Recordset’s current row, the VBUC then converts them to be the first Row of the first table in the DataSet, and the EWI is generated.
Note: In ADO, most of the time Recordset objects contain a single table retrieved from the Database. Therefore, the generated DataSets will only have one table in their Tables collections.
Recommendations
Review case by case to see if the first record of the DataTable object is actually the one intended to be used. If not, a change of logic might be required to achieve the functional equivalence between the original application and the upgraded one.
Also, turn on the ADODB-RDO feature in the VBUC (when available) to generate "Foreach" structures in places that match common recordset navigation patterns.
Sample VB6
Dim cn As Connection Dim rs1 As Recordset Dim cmd As Command Public Sub Example() Set cmd = New Command With cmd .ActiveConnection = cn .CommandText = "Select * from Customers where CustomerID = 42" .CommandType = adCmdText End With Set rs1 = cmd.Execute If rs1.EOF = False Then If rs1!Name <> "" Then Debug.Print rs1!Name If rs1!Email <> "" Then Debug.Print rs1!Email End If rs1.Close End Sub
Target VB.NET
Dim cn As SqlConnection Dim rs1 As DataSet Dim cmd As SqlCommand Public Sub ExampleOne() cmd = New SqlCommand() With cmd .Connection = cn .CommandText = "Select * from Customers where CustomerID = 42" .CommandType = CommandType.Text End With Dim adap As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection) rs1 = New DataSet("dsl") adap.Fill(rs1) If rs1.Tables(0).Rows.Count <> 0 Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. If rs1.Tables(0).Rows(0)("Name") <> "" Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. Debug.WriteLine(rs1.Tables(0).Rows(0)("Name")) End If 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. If rs1.Tables(0).Rows(0)("Email") <> "" Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. Debug.WriteLine(rs1.Tables(0).Rows(0)("Email")) End If End If End Sub
Target C#
Dim cn As SqlConnection Dim rs1 As DataSet Dim cmd As SqlCommand Public Sub ExampleOne() cmd = New SqlCommand() With cmd .Connection = cn .CommandText = "Select * from Customers where CustomerID = 42" .CommandType = CommandType.Text End With Dim adap As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection) rs1 = New DataSet("dsl") adap.Fill(rs1) If rs1.Tables(0).Rows.Count <> 0 Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. If rs1.Tables(0).Rows(0)("Name") <> "" Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. Debug.WriteLine(rs1.Tables(0).Rows(0)("Name")) End If 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. If rs1.Tables(0).Rows(0)("Email") <> "" Then 'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. Debug.WriteLine(rs1.Tables(0).Rows(0)("Email")) End If End If End Sub