All Products
Search
Document Center

Tablestore:Read a single row of data

Last Updated:May 12, 2026

This topic describes how to read a single row of data from a Tablestore data table by using the .NET SDK.

Usage notes

When you read data, you must provide the complete primary key value, including the value of any auto-increment primary key column.

Prerequisites

Initialize the Tablestore client

Method

public GetRowResponse GetRow(GetRowRequest request)

Asynchronous method:

public Task<GetRowResponse> GetRowAsync(GetRowRequest request)

GetRowRequest parameters

Parameter

Type

Description

tableName (Required)

string

The name of the data table.

primaryKey (Required)

PrimaryKey

The primary key information, including the names and values of primary key columns.

  • Supported data types for primary key columns include STRING, INTEGER, and BINARY.

  • The number and types of the primary key columns must be the same as those defined for the data table.

maxVersion (Optional)

int

The maximum number of versions to return. Default value: 1.

  • You cannot set both maxVersion and timeRange.

  • If the number of data versions that meet the query condition exceeds the specified maximum number of versions, the returned result contains the specified number of versions, ordered from newest to oldest.

timeRange (Optional)

TimeRange

The data version range.

  • You cannot set both maxVersion and timeRange.

  • Each attribute column in a Tablestore data table can have multiple data versions. If you specify a version range, the method returns only data within that range.

columnsToGet (Optional)

HashSet<string>

The data columns to read. The columns can be primary key columns or attribute columns.

  • If you do not specify columnsToGet, the method returns the entire row.

  • If you specify columnsToGet and the row does not contain any of the specified data columns, the operation returns null.

condition (Optional)

IColumnCondition

The filter condition. For more information, see Filter.

  • If you set both columnsToGet and condition, the system first applies the condition to filter the data. If the condition is met, the method returns only the data from the columns specified in columnsToGet.

Code example

This example reads a single row with the primary key value 'row1'.

try
{
    // Construct the primary key.
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };

    // Call the GetRow method to read the row.
    GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey);
    GetRowResponse getRowResponse = client.GetRow(getRowRequest);

    Console.WriteLine($"RequestId: {getRowResponse.RequestID}");
    Console.WriteLine($"Read CU Cost: {getRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"Write CU Cost: {getRowResponse.ConsumedCapacityUnit.Write}");
    Console.WriteLine($"Row Data: {getRowResponse.Row}");
}
catch (Exception ex)
{
    Console.WriteLine($"Get row failed, exception: {ex.Message}");
}
  • Specify a version range for the data to read. The method returns only data within the specified version range.

    TimeRange timeRange = new TimeRange
    {
        StartTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 86400 * 1000,
        EndTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
    };
    
    // Call the GetRow method to read the row.
    GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey, null, null, timeRange);
  • Specify the attribute columns to read.

    HashSet<string> columnsToGet = new HashSet<string> { "col2" };
    
    // Call the GetRow method to read the row.
    GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey, columnsToGet);