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 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
     
    '*********************************************
    'Example one: only the first row is being used.
     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

     

     '*********************************************

    'Example two: the recordset is being iterated
     Set cmd = New Command
     With cmd
        .ActiveConnection = cn
        .CommandText = "Select * from Customers"
        .CommandType = adCmdText
     End With

     Set rs1 = cmd.Execute
     
     If rs1.EOF = False Then
        For i = 1 To rs1.RecordCount
            If rs1!Name <> "" Then Debug.Print rs1!Name
            If rs1!Email <> "" Then Debug.Print rs1!Email
            rs1.MoveNext
        Next
     End If

     rs1.Close

    Target VB.NET

    Dim cn As SqlConnection

    '*********************************************
    'Example one: only the first row is being used.
    Dim cmd AsNew SqlCommand
    With cmd
        .Connection = cn
        .CommandText = "Select * from Customers where CustomerID = 42"
        .CommandType = CommandType.Text
    EndWith 

    Dim adap As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection)
    Dim rs1 As DataSet = New DataSet("dsl")
    adap.Fill(rs1) 

    IfNot (rs1.Tables(0).Rows.Count = 0) Then
        'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
        Debug.WriteLine(rs1.Tables(0).Rows(0)("Name"))
        'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
        Debug.WriteLine(rs1.Tables(0).Rows(0)("Email"))
    EndIf 

    '*********************************************
    'Example two: the recordset is being iterated
    cmd = New SqlCommand()
    With cmd
        .Connection = cn
        .CommandText = "Select * from Customers"
        .CommandType = CommandType.Text
    EndWith

    Dim adap_2 As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection)
    rs1 = New DataSet("dsl")
    adap_2.Fill(rs1)

    IfNot (rs1.Tables(0).Rows.Count = 0) Then
        For i AsInteger = 1 To rs1.Tables(0).Rows.Count
            'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
            Debug.WriteLine(rs1.Tables(0).Rows(0)("Name"))
            'UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
            Debug.WriteLine(rs1.Tables(0).Rows(0)("Email"))
            'UPGRADE_ISSUE: (2064) ADODB.Recordset method rs1.MoveNext was not upgraded. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2064
            UpgradeStubs.ADODB_Recordset.MoveNext(rs1)
        Next
    EndIf

    Expected VB.NET

    Dim cn As SqlConnection

    '*********************************************
    'Example one: only the first row is being used.
    Dim cmd AsNew SqlCommand
    With cmd
        .Connection = cn
        .CommandText = "Select * from Customers where CustomerID = 42"
        .CommandType = CommandType.Text
    EndWith

    Dim adap As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection)
    Dim rs1 As DataSet = New DataSet("dsl")
    adap.Fill(rs1)

    IfNot (rs1.Tables(0).Rows.Count = 0) Then
        'The Rows(0) is correct here!!
        Debug.WriteLine(rs1.Tables(0).Rows(0)("Name"))
        Debug.WriteLine(rs1.Tables(0).Rows(0)("Email"))
    EndIf 

    '*********************************************
    'Example two: the recordset is being iterated
    cmd = New SqlCommand()
    With cmd
        .Connection = cn
        .CommandText = "Select * from Customers"
        .CommandType = CommandType.Text
    EndWith 

    Dim adap_2 As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cmd.Connection)
    rs1 = New DataSet("dsl")
    adap_2.Fill(rs1) 

    IfNot (rs1.Tables(0).Rows.Count = 0) Then
        'In this case the for loop handles the row iteration, replace the Rows(0) by the for's loop variable
        For i AsInteger = 1 To rs1.Tables(0).Rows.Count
            Debug.WriteLine(rs1.Tables(0).Rows(i)("Name"))
            Debug.WriteLine(rs1.Tables(0).Rows(i)("Email"))
        Next
    EndIf

    Target C#

    SqlConnection cn = null;

    //*********************************************
    //Example one: only the first row is being used.
    SqlCommand cmd = newSqlCommand();
    cmd.Connection = cn;
    cmd.CommandText = "Select * from Customers where CustomerID = 42";
    cmd.CommandType = CommandType.Text;

    SqlDataAdapter adap = newSqlDataAdapter(cmd.CommandText, cmd.Connection);
    DataSet rs1 = newDataSet("dsl");
    adap.Fill(rs1);

    if (rs1.Tables[0].Rows.Count != 0)
    {
          //UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
          Debug.WriteLine(rs1.Tables[0].Rows[0]["Name"]);
          //UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
          Debug.WriteLine(rs1.Tables[0].Rows[0]["Email"]);
    }

    //*********************************************
    //Example two: the recordset is being iterated
    cmd = newSqlCommand();
    cmd.Connection = cn;
    cmd.CommandText = "Select * from Customers";
    cmd.CommandType = CommandType.Text; 

    SqlDataAdapter adap_2 = newSqlDataAdapter(cmd.CommandText, cmd.Connection);
    rs1 = newDataSet("dsl");
    adap_2.Fill(rs1); 

    if (rs1.Tables[0].Rows.Count != 0)
    {
          int tempForVar = rs1.Tables[0].Rows.Count;
          for (int i = 1; i <= tempForVar; i++)
          {
                //UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
                Debug.WriteLine(rs1.Tables[0].Rows[0]["Name"]);
                //UPGRADE_WARNING: (2077) Change the default 0 index in the Rows property with the correct one. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2077
                Debug.WriteLine(rs1.Tables[0].Rows[0]["Email"]);
                //UPGRADE_ISSUE: (2064) ADODB.Recordset method rs1.MoveNext was not upgraded. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2064
                UpgradeStubs.ADODB_Recordset.MoveNext(rs1);
          }
    }

    Expected C#

    SqlConnection cn = null;

    //*********************************************
    //Example one: only the first row is being used.
    SqlCommand cmd = newSqlCommand();
    cmd.Connection = cn;
    cmd.CommandText = "Select * from Customers where CustomerID = 42";
    cmd.CommandType = CommandType.Text; 

    SqlDataAdapter adap = newSqlDataAdapter(cmd.CommandText, cmd.Connection);
    DataSet rs1 = newDataSet("dsl");
    adap.Fill(rs1);

    if (rs1.Tables[0].Rows.Count != 0)
    {
        //The Rows[0] is correct here!!
          Debug.WriteLine(rs1.Tables[0].Rows[0]["Name"]);
          Debug.WriteLine(rs1.Tables[0].Rows[0]["Email"]);
    } 

    //*********************************************
    //Example two: the recordset is being iterated
    cmd = newSqlCommand();
    cmd.Connection = cn;
    cmd.CommandText = "Select * from Customers";
    cmd.CommandType = CommandType.Text; 

    SqlDataAdapter adap_2 = newSqlDataAdapter(cmd.CommandText, cmd.Connection);
    rs1 = newDataSet("dsl");
    adap_2.Fill(rs1);

    if (rs1.Tables[0].Rows.Count != 0)
    {
          int tempForVar = rs1.Tables[0].Rows.Count;
        //In this case the for loop handles the row iteration, replace the Rows[0] by the for's loop variable
          for (int i = 0; i < tempForVar; i++)
          {
                Debug.WriteLine(rs1.Tables[0].Rows[i]["Name"]);
                Debug.WriteLine(rs1.Tables[0].Rows[i]["Email"]);
          }
    }


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration