Learn how to use the .NET SDK to write a single row to a Tablestore table.
Prerequisites
Method
public PutRowResponse PutRow(PutRowRequest request)Asynchronous method:
public Task<PutRowResponse> PutRowAsync(PutRowRequest request)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);