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();
}
you can also GETDATE() function of sql it is predefine function of sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With