dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlDataReader Class / NextResult Method
Example

In This Topic
    NextResult Method (MySqlDataReader)
    In This Topic
    Advances the data reader to the next result, when reading the results of batch SQL statements.
    Syntax
    'Declaration
     
    Public Overrides Function NextResult() As Boolean
    public override bool NextResult()

    Return Value

    true if there are more result sets; otherwise, false.
    Remarks
    Used to process multiple results, which can be generated by executing batch SQL statements.

    By default, the MySqlDataReader is positioned on the first result.

    You can determine what result is current using CurrentResult property. Total amount of results stored in MySqlDataReader is represented by ResultCount property.

    Example
    The following example shows how to use NextResult to iterate through set of results.
    public void FetchResults(MySqlConnection myConnection)
    {
      MySqlCommand cmd = new MySqlCommand("SELECT EmpNo, EName FROM Test.Emp;SELECT * FROM Test.Dept");
      cmd.FetchAll = true;
      cmd.Connection = myConnection;
      myConnection.Open();
      try
      {
        MySqlDataReader reader = cmd.ExecuteReader();
        Console.WriteLine("Quantity of results: " + reader.ResultCount);
        while (true)
        {
          Console.WriteLine("---------------Result number " + reader.CurrentResult);
          while (reader.Read())
          {
            Console.Write(reader.CurrentRecord);
            Console.Write("\t"+reader[0]);
            Console.WriteLine("\t"+reader[1]);
          }
        if (!reader.NextResult())
          {
            break;
          }
          Console.ReadLine();
        }
      }
      finally
      {
        myConnection.Close();
      }
    }
    Public Sub FetchResults(ByVal myConnection As MySqlConnection)
      Dim cmd As MySqlCommand = New MySqlCommand("SELECT EmpNo, EName FROM Test.Emp;SELECT * FROM Test.Dept")
      cmd.FetchAll = True
      cmd.Connection = myConnection
      myConnection.Open()
      Try
        Dim reader As MySqlDataReader = cmd.ExecuteReader()
        Console.WriteLine(String.concat("Quantity of results: ", reader.ResultCount))
        While True
          Console.WriteLine(String.Concat("---------------Result number ", reader.CurrentResult))
          While reader.Read()
            Console.Write(reader.CurrentRecord)
            Console.Write(String.Concat(" ", reader(0)))
            Console.WriteLine(String.Concat(" ", reader(1)))
          End While
          If Not reader.NextResult() Then
            Exit While
          End If
          Console.ReadLine()
        End While
      Finally
        myConnection.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also