I am using the Google Sheets C# SDK client. I successfully initialized and read data from a spreadsheet using the SheetsService
variable you see below.
The problem is I need to save back some data to specific columns. The method below takes in a record and is supposed to update the columns for that record's row but nothing is ever written. I also verified no traffic occurs in Fiddler when this method is run.
public static void Update(DataRecord record)
{
var updateRequest = new BatchUpdateValuesRequest()
{
ValueInputOption = "RAW",
Data = new List<ValueRange>()
{
new ValueRange()
{
Range = $"'Form Responses'!C{record.RowId}",
Values = new List<IList<object>>()
{
new List<object>()
{
record.TransactionNumber
}
}
},
new ValueRange()
{
Range = $"'Form Responses'!G{record.RowId}:I{record.RowId}",
Values = new List<IList<object>>()
{
new List<object>()
{
record.Name,
record.DateOfBirth,
record.Address
}
}
}
}
};
SheetsService.Spreadsheets.Values.BatchUpdate(updateRequest, SpreadsheetId);
}
I also verified the scope of my SheetService is set to SheetsService.Scope.Spreadsheets
and meticulously verified that I had the correct spreadsheet ID, tab name, and cell range selection.
What am I missing? Why is there no network traffic for a batch update but there is traffic for reading? There is no error. It simply completes and moves on.
You're missing a .Execute()
call. The last line should read:
SheetsService.Spreadsheets.Values.BatchUpdate(updateRequest, SpreadsheetId).Execute();