All Products
Search
Document Center

Tablestore:Write a single row

Last Updated:Jun 22, 2026

Write a single row of data to a Tablestore table by using the .NET SDK.

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 primary key column names and values 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 names, values, and data versions.

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

  • Tablestore generates a data version automatically. 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

The following example writes a row with primary key value "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