I am struggling with proper parameter passing to a MySQL query. In MySQL workbench, my query works fine, but not in the C# code. I assume it is due to wrong parameter passing.
That's why I'd like to see what precisely do I pass to the cmd.ExecuteScalar()
method. But I can't figure out how to determine the cmd
string.
In debugger I only get query with formal parameters, not passed ones. And even by using cmd.ToString()
I get this nonsense:
MySql.Data.MySqlClient.MySqlCommand.
Here is my code:
string timeStampStr = timeStamp.ToString("yyyy-MM-dd hh:mm:ss");
...
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM plc WHERE plc.last_communication < @timeThreshold AND plc.id = @plcId", _conn);
cmd.Parameters.AddWithValue("@timeThreshold", timeStampStr); // Is this correct ? timeStampStr is a string
cmd.Parameters.AddWithValue("@plcId", plcId);
object result = cmd.ExecuteScalar();
Thank you !