This documentation is archived and is not being maintained.

DataTableReader.GetValue Method

Gets the value of the specified column in its native format.

Namespace: System.Data
Assembly: System.Data (in

public override Object GetValue (
	int ordinal
public Object GetValue (
	int ordinal
public override function GetValue (
	ordinal : int
) : Object
Not applicable.



The zero-based column ordinal

Return Value

The value of the specified column. This method returns DBNull for null columns.

Exception typeCondition


The index passed was outside the range of 0 to FieldCount - 1.


An attempt was made to retrieve data from a deleted row.


An attempt was made to read or access columns in a closed DataTableReader .

Although you can call IsDBNull to see if there are null values before calling this method, you do not have to do this.

The following example iterates through all the columns within the current row in a DataTableReader, displaying the contents of each column and the column name. Generally, if your intent is to work with all the columns within a row retrieved by a DataTableReader, consider using the GetValues method instead, because it is more efficient.

private static void GetAllValues(DataTableReader reader)
    // Given a DataTableReader, retrieve the value of 
    // each column, and display the name, value, and type.
    // Make sure you have called reader.Read at least once before
    // calling this procedure.

    // Loop through all the columns.
    object value = null;
    for (int i = 0; i < reader.FieldCount; i++)
        if (reader.IsDBNull(i))
            value = "<NULL>";
            value = reader.GetValue(i);
        Console.WriteLine("{0}: {1} ({2})", reader.GetName(i), 
            value, reader.GetFieldType(i).Name);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0