All Products
Search
Document Center

Tablestore:Write a single row

Last Updated:May 12, 2026

Learn how to use the .NET SDK to write a single row to a Tablestore table.

Prerequisites

Initialize a Tablestore client

Method

public PutRowResponse PutRow(PutRowRequest request)

Asynchronous method:

public Task<PutRowResponse> PutRowAsync(PutRowRequest request)

PutRowRequest parameters

Parameter

Type

Description

tableName (Required)

string

The table name.

primaryKey (Required)

PrimaryKey

The names and values of the primary key columns for the row.

  • Valid data types for primary key columns are STRING, INTEGER, and BINARY.

  • The number and data types of the primary key columns must match the table's schema.

columns (Optional)

AttributeColumns

The attribute columns, including their names, values, and data versions.

  • Valid data types for attribute columns are STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

  • By default, Tablestore automatically generates a data version. You can also specify a custom version. For more information, see Data version and time to live.

condition (Required)

Condition

The condition for the write operation. For more information, see conditional writes.

Sample code

This example writes a row with a primary key value of "row1" to the "test_table" table.

try
{
    // Construct the primary key.
    PrimaryKey primaryKey = new PrimaryKey
    {
        { "id", new ColumnValue("row1") }
    };
    // Specify a condition for the write operation. 
    // RowExistenceExpectation.IGNORE skips the row existence check.
    Condition condition = new Condition(RowExistenceExpectation.IGNORE);

    // Call the PutRow method to write the row.
    PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, null);
    PutRowResponse putRowResponse = client.PutRow(putRowRequest);
    Console.WriteLine($"* RequestId: {putRowResponse.RequestID}");
    Console.WriteLine($"* Read CU Cost: {putRowResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"* Write CU Cost: {putRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
    Console.WriteLine($"Put row failed, exception: {ex.Message}");
}
  • Add attribute columns.

    AttributeColumns columns = new AttributeColumns
    {
        { "col1", new ColumnValue("val1") }
    };
    
    // Create a PutRowRequest.
    PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, columns);

Related topics

Batch write data