MySqlDataReader Class |

System.Data.CommonDbDataReader
MySql.Data.MySqlClientMySqlDataReader
Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.9.9

public sealed class MySqlDataReader : DbDataReader, IDisposable, IDataReader, IDataRecord
Public NotInheritable Class MySqlDataReader Inherits DbDataReader Implements IDisposable, IDataReader, IDataRecord
public ref class MySqlDataReader sealed : public DbDataReader, IDisposable, IDataReader, IDataRecord
[<SealedAttribute>] type MySqlDataReader = class inherit DbDataReader interface IDisposable interface IDataReader interface IDataRecord end
The MySqlDataReader type exposes the following members.

Name | Description | |
---|---|---|
![]() | Depth |
Gets a value indicating the depth of nesting for the current row. This method is not
supported currently and always returns 0.
(Overrides DbDataReaderDepth.) |
![]() | FieldCount |
Gets the number of columns in the current row.
(Overrides DbDataReaderFieldCount.) |
![]() | HasRows |
Gets a value indicating whether the MySqlDataReader contains one or more rows.
(Overrides DbDataReaderHasRows.) |
![]() | IsClosed |
Gets a value indicating whether the data reader is closed.
(Overrides DbDataReaderIsClosed.) |
![]() | ItemInt32 |
Overloaded. Gets the value of a column in its native format.
In C#, this property is the indexer for the MySqlDataReader class.
(Overrides DbDataReaderItemInt32.) |
![]() | ItemString |
Gets the value of a column in its native format.
[C#] In C#, this property is the indexer for the MySqlDataReader class.
(Overrides DbDataReaderItemString.) |
![]() | RecordsAffected |
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
(Overrides DbDataReaderRecordsAffected.) |
![]() | VisibleFieldCount | (Inherited from DbDataReader.) |

Name | Description | |
---|---|---|
![]() | Close |
Closes the MySqlDataReader object.
(Overrides DbDataReaderClose.) |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() | Dispose | |
![]() | Dispose(Boolean) | (Inherited from DbDataReader.) |
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | (Overrides ObjectFinalize.) |
![]() | GetBoolean(Int32) |
Gets the value of the specified column as a Boolean.
(Overrides DbDataReaderGetBoolean(Int32).) |
![]() | GetBoolean(String) |
Gets the value of the specified column as a Boolean.
|
![]() | GetByte(Int32) |
Gets the value of the specified column as a byte.
(Overrides DbDataReaderGetByte(Int32).) |
![]() | GetByte(String) |
Gets the value of the specified column as a byte.
|
![]() | GetBytes |
Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset.
(Overrides DbDataReaderGetBytes(Int32, Int64, Byte, Int32, Int32).) |
![]() | GetChar(Int32) |
Gets the value of the specified column as a single character.
(Overrides DbDataReaderGetChar(Int32).) |
![]() | GetChar(String) |
Gets the value of the specified column as a single character.
|
![]() | GetChars |
Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.
(Overrides DbDataReaderGetChars(Int32, Int64, Char, Int32, Int32).) |
![]() | GetData | (Inherited from DbDataReader.) |
![]() | GetDataTypeName |
Gets the name of the source data type.
(Overrides DbDataReaderGetDataTypeName(Int32).) |
![]() | GetDateTime(Int32) |
Gets the value of the specified column as a DateTime object.
(Overrides DbDataReaderGetDateTime(Int32).) |
![]() | GetDateTime(String) |
Gets the value of the specified column as a DateTime object.
|
![]() | GetDbDataReader | (Inherited from DbDataReader.) |
![]() | GetDecimal(Int32) |
Gets the value of the specified column as a Decimal object.
(Overrides DbDataReaderGetDecimal(Int32).) |
![]() | GetDecimal(String) |
Gets the value of the specified column as a Decimal object.
|
![]() | GetDouble(Int32) | Gets the value of the specified column as a double-precision floating point number. (Overrides DbDataReaderGetDouble(Int32).) |
![]() | GetDouble(String) | Gets the value of the specified column as a double-precision floating point number. |
![]() | GetEnumerator |
Returns an IEnumerator that iterates through the MySqlDataReader.
(Overrides DbDataReaderGetEnumerator.) |
![]() | GetFieldType(Int32) |
Gets the Type that is the data type of the object.
(Overrides DbDataReaderGetFieldType(Int32).) |
![]() | GetFieldType(String) | |
![]() | GetFieldValueT | (Inherited from DbDataReader.) |
![]() | GetFieldValueAsyncT(Int32) | (Inherited from DbDataReader.) |
![]() | GetFieldValueAsyncT(Int32, CancellationToken) | (Inherited from DbDataReader.) |
![]() | GetFloat(Int32) |
Gets the value of the specified column as a single-precision floating point number.
(Overrides DbDataReaderGetFloat(Int32).) |
![]() | GetFloat(String) |
Gets the value of the specified column as a single-precision floating point number.
|
![]() | GetGuid(Int32) | (Overrides DbDataReaderGetGuid(Int32).) |
![]() | GetGuid(String) | |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetInt16(Int32) | Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReaderGetInt16(Int32).) |
![]() | GetInt16(String) | Gets the value of the specified column as a 16-bit signed integer. |
![]() | GetInt32(Int32) | Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReaderGetInt32(Int32).) |
![]() | GetInt32(String) | Gets the value of the specified column as a 32-bit signed integer. |
![]() | GetInt64(Int32) | Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReaderGetInt64(Int32).) |
![]() | GetInt64(String) | Gets the value of the specified column as a 64-bit signed integer. |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetMySqlDateTime(Int32) |
Gets the value of the specified column as a MySqlDateTime object.
|
![]() | GetMySqlDateTime(String) |
Gets the value of the specified column as a MySqlDateTime object.
|
![]() | GetMySqlDecimal(Int32) | |
![]() | GetMySqlDecimal(String) | |
![]() | GetMySqlGeometry(Int32) | |
![]() | GetMySqlGeometry(String) | |
![]() | GetName |
Gets the name of the specified column.
(Overrides DbDataReaderGetName(Int32).) |
![]() | GetOrdinal |
Gets the column ordinal, given the name of the column.
(Overrides DbDataReaderGetOrdinal(String).) |
![]() | GetProviderSpecificFieldType | (Inherited from DbDataReader.) |
![]() | GetProviderSpecificValue | (Inherited from DbDataReader.) |
![]() | GetProviderSpecificValues | (Inherited from DbDataReader.) |
![]() | GetSByte(Int32) |
Gets the value of the specified column as a sbyte.
|
![]() | GetSByte(String) |
Gets the value of the specified column as a sbyte.
|
![]() | GetSchemaTable |
Returns a DataTable that describes the column metadata of the MySqlDataReader.
(Overrides DbDataReaderGetSchemaTable.) |
![]() | GetStream | (Inherited from DbDataReader.) |
![]() | GetString(Int32) |
Gets the value of the specified column as a String object.
(Overrides DbDataReaderGetString(Int32).) |
![]() | GetString(String) |
Gets the value of the specified column as a String object.
|
![]() | GetTextReader | (Inherited from DbDataReader.) |
![]() | GetTimeSpan(Int32) |
Gets the value of the specified column as a TimeSpan object.
|
![]() | GetTimeSpan(String) |
Gets the value of the specified column as a TimeSpan object.
|
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetUInt16(Int32) | Gets the value of the specified column as a 16-bit unsigned integer. |
![]() | GetUInt16(String) | Gets the value of the specified column as a 16-bit unsigned integer. |
![]() | GetUInt32(Int32) | Gets the value of the specified column as a 32-bit unsigned integer. |
![]() | GetUInt32(String) | Gets the value of the specified column as a 32-bit unsigned integer. |
![]() | GetUInt64(Int32) | Gets the value of the specified column as a 64-bit unsigned integer. |
![]() | GetUInt64(String) | Gets the value of the specified column as a 64-bit unsigned integer. |
![]() | GetValue |
Gets the value of the specified column in its native format.
(Overrides DbDataReaderGetValue(Int32).) |
![]() | GetValues |
Gets all attribute columns in the collection for the current row.
(Overrides DbDataReaderGetValues(Object).) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | IsDBNull |
Gets a value indicating whether the column contains non-existent or missing values.
(Overrides DbDataReaderIsDBNull(Int32).) |
![]() | IsDBNullAsync(Int32) | (Inherited from DbDataReader.) |
![]() | IsDBNullAsync(Int32, CancellationToken) | (Inherited from DbDataReader.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | NextResult |
Advances the data reader to the next result, when reading the results of batch SQL statements.
(Overrides DbDataReaderNextResult.) |
![]() | NextResultAsync | (Inherited from DbDataReader.) |
![]() | NextResultAsync(CancellationToken) | (Inherited from DbDataReader.) |
![]() | Read |
Advances the MySqlDataReader to the next record.
(Overrides DbDataReaderRead.) |
![]() | ReadAsync | (Inherited from DbDataReader.) |
![]() | ReadAsync(CancellationToken) | (Inherited from DbDataReader.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |

To create a MySQLDataReader, you must call the ExecuteReader method of the MySqlCommand object, rather than directly using a constructor.
While the MySqlDataReader is in use, the associated MySqlConnection is busy serving the MySqlDataReader, and no other operations can be performed on the MySqlConnection other than closing it. This is the case until the Close method of the MySqlDataReader is called.
IsClosed and RecordsAffected are the only properties that you can call after the MySqlDataReader is closed. Though the RecordsAffected property may be accessed at any time while the MySqlDataReader exists, always call Close before returning the value of RecordsAffected to ensure an accurate return value.
For optimal performance, MySqlDataReader avoids creating unnecessary objects or making unnecessary copies of data. As a result, multiple calls to methods such as GetValue(Int32) return a reference to the same object. Use caution if you are modifying the underlying value of the objects returned by methods such as GetValue.

public void ReadMyData(string myConnString) { string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders"; MySqlConnection myConnection = new MySqlConnection(myConnString); MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection); myConnection.Open(); MySqlDataReader myReader; myReader = myCommand.ExecuteReader(); // Always call Read before accessing data. while (myReader.Read()) { Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1)); } // always call Close when done reading. myReader.Close(); // Close the connection when done with it. myConnection.Close(); }
Public Sub ReadMyData(myConnString As String) Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders" Dim myConnection As New MySqlConnection(myConnString) Dim myCommand As New MySqlCommand(mySelectQuery, myConnection) myConnection.Open() Dim myReader As MySqlDataReader myReader = myCommand.ExecuteReader() ' Always call Read before accessing data. While myReader.Read() Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1))) End While ' always call Close when done reading. myReader.Close() ' Close the connection when done with it. myConnection.Close() End Sub 'ReadMyData
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
