if you please help me out my error is:
Conversion failed when converting date and/or time from character string.
my database column is of type datetime
Use a parameterized query and you won't have to worry about date formats, or sql injection, and use using
to ensure your connection is disposed.
using (var connection = new SqlConnection(yourConnectionString))
using (var command = connection.CreateCommand())
{
command.CommandText = "insert into YourTable(Col1, Col2) values(@val1, @val2)";
command.Parameters.AddWithValue("@val1", 123);
command.Parameters.AddWithValue("@val2", DateTime.Now);
connection.Open();
command.ExecuteNonQuery();
}
ctime
variable at this point? That should give a clue as to why it throws the error. – Dan J