System.Data.Common.DbCommand.ExecuteReader C# (CSharp) Method

ExecuteReader() public method

public ExecuteReader ( ) : System.Data.Common.DbDataReader
return System.Data.Common.DbDataReader
        public DbDataReader ExecuteReader() => ExecuteDbDataReader(CommandBehavior.Default);

Same methods

DbCommand::ExecuteReader ( CommandBehavior behavior ) : System.Data.Common.DbDataReader

Usage Example

コード例 #1
0
    // executes a command and returns the results as a DataTable object
    public static DataTable ExecuteSelectCommand(DbCommand command)
    {
        // The DataTable to be returned
        DataTable table;
        // Execute the command making sure the connection gets closed in the end
        try
        {
            // Open the data connection
            command.Connection.Open();
            // Execute the command and save the results in a DataTable
            DbDataReader reader = command.ExecuteReader();
            table = new DataTable();
            table.Load(reader);

            // Close the reader
            reader.Close();
        }
        catch (Exception ex)
        {
            Utilities.LogError(ex);
            throw;
        }
        finally
        {
            // Close the connection
            command.Connection.Close();
        }
        return table;
    }
All Usage Examples Of System.Data.Common.DbCommand::ExecuteReader