I always have problems with dates when wanting to pass them as a parameter to a SQL statement, I try to use a previous variable, a Convert
or a Cast
but I never find the correct way.
I have the following statement in C # where I am building an Update statement and I am sending 3 parameters, of which two are numeric values and the last one is the date in question.
UpdateStatement = "UPDATE Productos SET PrecioUnitario = " + nPrecioUnitario.ToString() + ", FactorVenta = " + nFactorVenta.ToString() + ", PrecioUnitarioFecha = CONVERT(DateTime,'" + dFecha.ToString() + "',103) WHERE ProductoId = " + nProductoId;
The error I get is the following:
Conversion failed when converting datetime from character string.
It is not a format issue because we are May 18 and the date is coming 05/18/2016 12:00:00. First try to leave it without converting, then I put it in quotation marks and I added the Convert and I do not know at the end if there is any correct way to make a date happen directly and without these problems.
Any ideas?