dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlCommand Class / ExecuteReader Method / ExecuteReader(CommandBehavior) Method
One of the System.Data.CommandBehavior values.
Example

On this page
    ExecuteReader(CommandBehavior) Method
    On this page
    Sends the CommandText to the Connection, and builds a MySqlDataReader using one of the System.Data.CommandBehavior values.
    Syntax
    'Declaration
     
    Public Overloads Shadows Function ExecuteReader( _
       ByVal behavior As CommandBehavior _
    ) As MySqlDataReader
    public new MySqlDataReader ExecuteReader( 
       CommandBehavior behavior
    )

    Parameters

    behavior
    One of the System.Data.CommandBehavior values.

    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. The System.Data.CommandBehavior is then set to CloseConnection.
    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(CommandBehavior.CloseConnection);
      while(mySqlReader.Read())
      {
        Console.WriteLine(mySqlReader.GetString(0));
      }
      mySqlReader.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(CommandBehavior.CloseConnection)
      While mySqlReader.Read()
        Console.WriteLine(mySqlReader.GetString(0))
      End While
      mySqlReader.Close()
    End Sub
    See Also