How to insert date and time in European format into SQL Server from C#? -


here's query:

string sql = @"insert my_table(date)                              values (convert(datetime, '{0}')";  sql = string.format(sql, mydate); 

mydate c# datetime object , has value before string.format:

enter image description here

my_table has date column datetime type.

i got error:

the conversion of varchar data type datetime data type resulted in out-of-range value.

i need store mydatevalue in format like: 31/12/2013 23:59:00 my_table.

better use sql parameters

string sql = @"insert my_table(date)                              values (@date)"; 

add parameter sqlcommand sqlparametercollection.addwithvalue method

command.parameters.addwithvalue("@date", mydate); 

or, sqlparametercollection.add method

   command.parameters.add("@date",sqldbtype.datetime).value = mydate 

Comments