I'm getting an error
Conversion failed when converting from a character string to unique identifier.
and I don't even have any conversion of dates, so I'm pretty lost here.
I am using a parametrized query and adding 2 values that come from a datarowview. In this case if I debug and check the value for the date I get it in this format {8/17/2016 9:08:44 PM}
string query = @"SELECT TOP 1
SensorValue,
ActivityDateTime,
(Select TimeAlert from Vehicle_config
where VehicleID = '@guid') as TimeAlert,
(Select DistanceAlert from Vehicle_config
where VehicleID = '@guid') as DistanceAlert,
(Select TimeInterval from Vehicle_config
where VehicleID = '@guid') as TimeInterval,
(Select DistanceInterval from Vehicle_config
where VehicleID = '@guid') as DistanceInterval,
(Select AlertFlag from Vehicle_config
where VehicleID = '@guid') as AlertFlag,
(Select Litros from Vehicle_config
where VehicleID = '@guid') as Litros
FROM
navman_Fuel_activity
WHERE
ActivityDateTime < DATEADD(MI, -5, @date)
AND VehicleId = '@guid'
ORDER BY ActivityDateTime DESC;";
using (SqlConnection sqlConn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(query, sqlConn))
{
cmd.Parameters.AddWithValue("date", (DateTime)row["ActivityDateTime"]);
cmd.Parameters.AddWithValue("guid",(Guid)row["VehicleID"]);
sqlConn.Open();
using (var reader = cmd.ExecuteReader())
{
if (reader.Read()) // here is where I get the error
cmd.Parameters.AddWithValue("guid",(Guid)row["VehicleID"]);row["VehicleID"]