C#'s DateTime
is in dd.MM.yyyy hh:mm:ss
format so it is not compatible with the one SQL Server uses. I want it to be in yyyy-MM-dd hh:mm:ss
format. Does anyone know how I can do this?
DateTime odt = new DateTime(year, month, day, hour, minute, second);
string odt2= odt.ToString("yyyy-MM-dd hh:mm:ss");
Here is the stored procedure I'm using;
ALTER PROCEDURE [dbo].[SELECT_ORDERSTATUS_BY_ORDERDATETIME]
@ORDERDATETIME DateTime
AS
SELECT dbo.OrderTable.Status
FROM dbo.OrderTable
WHERE OrderDateTime = @ORDERDATETIME
And here is my C# code. ExecuteScalar
returns null value and I think it's because DateTime
's simply do not match.
DateTime odt = new DateTime(year, month, day, hour, minute, second);
SqlConnection con = generateConnectionString();
con.Open();
SqlCommand command = generateCommand("SELECT_ORDERSTATUS_BY_ORDERDATETIME", con);
SqlParameter paramOrderDateTime = new SqlParameter("@ORDERDATETIME", odt);
command.Parameters.Add(paramOrderDateTime);
string status = (string)command.ExecuteScalar();
currentstatusTextbox.Text = status;
con.Close();