Hi,
trying to query in influxDB using C# SQL query, but it’s failing. same generated query when running on influxDB directly works well but through C# is giving below error:
Service layer: Error getting data to InfluxDB: Nullable object must have a value. Query generated something like below:
SELECT mean(CAST(“236” as float)) AS “236_mean”
FROM “STRM_xxx”
WHERE “UnitKey” = ‘xxx’
AND time >= ‘ABC’ AND time <=‘XYZ’
where 236 is fieldid for fields like voltage,current etc.
not sure why same query works in DB but not though C# SQL
Hello @ketakibendre,
What version of InfluxDB are you using?
Are you using C# .NET client library for InfluxDB 3 | InfluxDB 3 Core Documentation?
Are you querying timestamps like this?
WHERE
time >= '2022-01-01T08:00:00Z'
AND time <= '2022-01-01T10:00:00Z'
With that format?
This should work
using System.Threading.Tasks;
using InfluxDB3.Client;
using InfluxDB3.Client.Write;
// Initialize the client
const string host = "https://your-influxdb-host";
const string token = "your-token";
const string database = "your-database";
using var client = new InfluxDBClient(host, token: token, database: database);
// Query using SQL
const string sql = "SELECT mean(CAST(\"236\" as float)) AS \"236_mean\" FROM \"STRM_xxx\" WHERE \"UnitKey\" = 'xxx' AND time >= 'ABC' AND time <='XYZ'";
await foreach (var row in client.Query(query: sql))
{
// Process each row
Console.WriteLine($"{row[0]}, {row[1]}, {row[2]}");
}
Can you share your code?