dotConnect for SQLite Documentation
Devart.Data.SQLite Namespace / SQLiteDataReader Class / Close Method
Example

On this page
    Close Method (SQLiteDataReader)
    On this page
    Closes the SQLiteDataReader 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 SQLiteDataReader in order to use the associated SQLiteConnection for any other purpose.
    Example
    The following example creates a SQLiteConnection, a SQLiteCommand, and a SQLiteDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the SQLiteDataReader, then the SQLiteConnection.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT DeptNo, DName FROM Dept";
      SQLiteConnection sqLiteConnection = new SQLiteConnection(myConnString);
      SQLiteCommand sqLiteCommand = new SQLiteCommand(mySelectQuery,sqLiteConnection);
      sqLiteConnection.Open();
      SQLiteDataReader sqLiteReader;
      sqLiteReader = sqLiteCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (sqLiteReader.Read()) {
        Console.WriteLine(sqLiteReader.GetInt32(0) + ", " + sqLiteReader.GetString(1));
      }
      // always call Close when done reading.
      sqLiteReader.Close();
      // Close the connection when done with it.
      sqLiteConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Dept"
      Dim sqLiteConnection As New SQLiteConnection(myConnString)
      Dim sqLiteCommand As New SQLiteCommand(mySelectQuery, sqLiteConnection)
      sqLiteConnection.Open()
      Dim sqLiteReader As SQLiteDataReader
      sqLiteReader = sqLiteCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While sqLiteReader.Read()
        Console.WriteLine(sqLiteReader.GetInt32(0).ToString() + ", " _
          + sqLiteReader.GetString(1))
      End While
      ' always call Close when done reading.
      sqLiteReader.Close()
      ' Close the connection when done with it.
      sqLiteConnection.Close()
    End Sub
    See Also