dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2DataReader Class / GetValues Method
An array of System.Object into which to copy the attribute column values.
Example

In This Topic
    GetValues Method (DB2DataReader)
    In This Topic
    Gets all column values for the current row.
    Syntax
    'Declaration
     
    Public Overrides Function GetValues( _
       ByVal values() As Object _
    ) As Integer
    public override int GetValues( 
       object[] values
    )

    Parameters

    values
    An array of System.Object into which to copy the attribute column values.

    Return Value

    The number of instances of System.Object in the array.
    Remarks
    For most applications, the GetValues method provides an efficient way for retrieving all column values, rather than retrieving each column value individually.

    You can pass an System.Object array that contains fewer than the number of column values contained in the resulting row. Only the amount of data the System.Object array holds is copied to the array. You can also pass an System.Object array whose length is more than the number of columns contained in the resulting row.

    This method returns System.DBNull for redundant array elements.

    Example
    The example shows how to retrieve several fields at once. Note that only the first three fields are retrieved, though there may be more in the table.
    public void GetObjects(DB2Connection db2Connection)
    {
      DB2Command cmd = new DB2Command("SELECT * FROM Emp");
      cmd.Connection = db2Connection;
      db2Connection.Open();
      try
      {
        DB2DataReader reader = cmd.ExecuteReader();
        reader.Read();
        object[] objs = new object[3];
        int quant = reader.GetValues(objs);
        for (int i=0;i < quant;i++)
        {
          Console.WriteLine(objs[i]);
        }
        reader.Close();
      }
      finally
      {
        db2Connection.Close();
      }
    }
    Public Sub GetObjects(ByVal db2Connection As DB2Connection)
      Dim cmd As DB2Command = New DB2Command("SELECT * FROM Dept")
      cmd.Connection = db2Connection
      db2Connection.Open()
      Try
        Dim reader As DB2DataReader = cmd.ExecuteReader()
        reader.Read()
        Dim objs(3) As Object
        Dim quant As Integer = reader.GetValues(objs)
        Dim i As Integer
        For i = 0 To quant - 1
          Console.WriteLine(objs(i))
        Next i
        reader.Close()
      Finally
        db2Connection.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also