DB2ResultSet.Close Method

Closes the DB2ResultSet object.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[Visual Basic]
Public Sub Close()
[C#]
public void Close();
[C++]
public: void Close();
[JScript]
public function Close();

Remarks

You must explicitly call the Close method when you are finished using a DB2®DataReader or DB2ResultSet to use the associated DB2Command for any other purpose.

Example

[Visual Basic, C#] The following example creates a DB2Connection , a DB2Command , and a DB2DataReader . The example reads through the data, writing it out to the console. Finally, the example closes the DB2DataReader, then the DB2Connection.

[Visual Basic]
Public Sub ReadMyData(myConnString As String)
    Dim mySelectQuery As String = "SELECT ID, NAME FROM STAFF"
    Dim myConnection As New DB2Connection(myConnString)
    Dim myCommand As New DB2Command(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As DB2DataReader
    myReader = myCommand.ExecuteReader()
    ' Always call Read before accessing data.
    While myReader.Read()
        Console.WriteLine(myReader.GetInt16(0).ToString() + ", " _
           + myReader.GetString(1))
    End While
    ' always call Close when done reading.
    myReader.Close()
    ' Close the connection when done with it.
    myConnection.Close()
End Sub

[C#]
public void ReadMyData(string myConnString)
{
   string mySelectQuery = "SELECT ID, NAME FROM STAFF";
   DB2Connection myConnection = new DB2Connection(myConnString);
   DB2Command myCommand = new DB2Command(mySelectQuery,myConnection);
   myConnection.Open();
   DB2DataReader myReader;
   myReader = myCommand.ExecuteReader();
   // Always call Read before accessing data.
   while (myReader.Read()) {
      Console.WriteLine(myReader.GetInt16(0) + ", " + myReader.GetString(1));
   }
   // always call Close when done reading.
   myReader.Close();
   // Close the connection when done with it.
   myConnection.Close();
}