dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlCommand Class / ExecuteReader Method / ExecuteReader() Method
Example

On this page
    ExecuteReader() Method
    On this page
    Sends the CommandText to the Connection and builds a MySqlDataReader.
    Syntax
    'Declaration
     
    Public Overloads Shadows Function ExecuteReader() As MySqlDataReader
    public new MySqlDataReader ExecuteReader()

    Return Value

    A MySqlDataReader object.
    Remarks

    When FetchAll property is false the following restriction takes place. While the MySqlDataReader is in use, the associated MySqlConnection is busy serving the MySqlDataReader. While in this state, no operations can be performed on the MySqlConnection except closing. This is the case until the MySqlDataReader.Close method of the MySqlDataReader is called.

    Example
    The following example creates a MySqlCommand, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source.
    public void CreateMySqlDataReader(string mySelectQuery,string mySqlConnectionString)
    {
      MySqlConnection mySqlConnection = new MySqlConnection(mySqlConnectionString);
      MySqlCommand mySqlCommand = new MySqlCommand(mySelectQuery, mySqlConnection);
      mySqlCommand.Connection.Open();
      MySqlDataReader mySqlReader = mySqlCommand.ExecuteReader();
      try
      {
        while(mySqlReader.Read())
        {
          Console.WriteLine(mySqlReader.GetString(0));
        }
      }
      finally
      {
        mySqlReader.Close();
        mySqlConnection.Close();
      }
    }
    Public Sub CreateMySqlDataReader(mySelectQuery As String, _
    mySqlConnectionString As String)
      Dim mySqlConnection As New MySqlConnection(mySqlConnectionString)
      Dim mySqlCommand As New MySqlCommand(mySelectQuery, mySqlConnection)
      mySqlCommand.Connection.Open()
      Dim mySqlReader As MySqlDataReader = mySqlCommand.ExecuteReader()
      Try
        While mySqlReader.Read()
          Console.WriteLine(mySqlReader.GetString(0))
        End While
      Finally
        mySqlReader.Close()
        mySqlConnection.Close()
      End Try
    End Sub
    See Also