How do I insert a datetime value into a SQL database table where the type of the column is datetime?
question from:https://stackoverflow.com/questions/1032495/insert-datetime-value-in-sql-database-with-c-sharpHow do I insert a datetime value into a SQL database table where the type of the column is datetime?
question from:https://stackoverflow.com/questions/1032495/insert-datetime-value-in-sql-database-with-c-sharpThe following should work and is my recommendation (parameterized query):
DateTime dateTimeVariable = //some DateTime value, e.g. DateTime.Now;
SqlCommand cmd = new SqlCommand("INSERT INTO <table> (<column>) VALUES (@value)", connection);
cmd.Parameters.AddWithValue("@value", dateTimeVariable);
cmd.ExecuteNonQuery();