Skip to main content

Hi All,

I am trying to update data in RAW table. I am using below code but after executing it either column values are not modified or sometimes all the columns shrink under one columns as ({} columns) and column data is also not updated in that case.

 

var row = confModel.RawRow as RawRow<Dictionary<string, JsonElement>>;
if (row == null)
{
    return;
}

var currentDate = DateTime.Now;
var utcDate = currentDate.ToUniversalTime().ToString("u").Replace(" ", "T");
row.ColumnsmUpdatedBy] = GetJsonElement(JsonValue.Create("SYSTEM"));
row.ColumnsmSimulationStatus] = GetJsonElement(JsonValue.Create(status.ToString()));
row.ColumnsmUpdatedDate] = GetJsonElement(JsonValue.Create(utcDate));
var rawRowCreateColl = new List<RawRowCreate<RawRow<Dictionary<string, JsonElement>>>>();
var rawRowCreate = new RawRowCreate<RawRow<Dictionary<string, JsonElement>>>();
rawRowCreate.Key = confModel.RowKey;
rawRowCreate.Columns = row;
rawRowCreateColl.Add(rawRowCreate);

try
{
    SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
}
catch (Exception e)
{
    Console.WriteLine($"Error: {e.Message}");
}

 

@Adarsh Dhiman  can you change the try catch method as below and try again?

try
{
await SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
Console.WriteLine("Data updated successfully.");
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}

 


@Mithila Jayalath External My method is not async so I am not using await on CreateRowsAsync.


@Adarsh Dhiman isn’t the CreateRowsAsync method is an async mothod in the Cognite SDK to create rows in a table? 


@Mithila Jayalath External In case if you are writing non async code you can call async code without await and can use Wait on that task. I missed that wait. Let me try with it.

var createRowTask = SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
createRowTask.Wait();


After update all the columns shrink into one.

 


You are explicitly creating a `RawRowCreate<RawRow<Dictionary<string, JsonElement>>>`, in other words, a raw row where the columns are a full `RawRow`. You want to make it a `RawRowCreate<Dictionary<string, JsonElement>>`, and move only the `Columns` part of the retrieved row over.


@Einar Omang Thanks it worked.


Reply