dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlDataReader Class / Close() Method
Example

On this page
    Close() Method
    On this page
    Closes the MySqlDataReader object.
    Syntax
    'Declaration
     
    Public Overrides Sub Close() 
    public override void Close()
    Remarks
    You must explicitly call the Close method after you have finished working with the MySqlDataReader in order to use the associated MySqlConnection for any other purpose.
    Example
    The following example creates a MySqlConnection, a MySqlCommand, and a MySqlDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the MySqlDataReader, then the MySqlConnection.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept";
      MySqlConnection mySqlConnection = new MySqlConnection(myConnString);
      MySqlCommand mySqlCommand = new MySqlCommand(mySelectQuery,mySqlConnection);
      mySqlConnection.Open();
      MySqlDataReader mySqlReader;
      mySqlReader = mySqlCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (mySqlReader.Read()) {
        Console.WriteLine(mySqlReader.GetInt32(0) + ", " + mySqlReader.GetString(1));
      }
      // always call Close when done reading.
      mySqlReader.Close();
      // Close the connection when done with it.
      mySqlConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim mySqlConnection As New MySqlConnection(myConnString)
      Dim mySqlCommand As New MySqlCommand(mySelectQuery, mySqlConnection)
      mySqlConnection.Open()
      Dim mySqlReader As MySqlDataReader
      mySqlReader = mySqlCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While mySqlReader.Read()
        Console.WriteLine(mySqlReader.GetInt32(0).ToString() + ", " _
          + mySqlReader.GetString(1))
      End While
      ' always call Close when done reading.
      mySqlReader.Close()
      ' Close the connection when done with it.
      mySqlConnection.Close()
    End Sub
    See Also