DateTime in SqlServer VisualStudio C#

Posted by menacheb on Stack Overflow See other posts from Stack Overflow or by menacheb
Published on 2010-04-14T10:09:51Z Indexed on 2010/04/14 10:13 UTC
Read the original article Hit count: 238

Filed under:
|
|

Hi,
I Have a DataBase in my project With Table named 'ProcessData' and columns named 'Start_At' (Type: DateTime) and 'End_At' (Type: DateTime) .
When I try to enter a new record into this table, it enter the data in the following format: 'YYYY/MM/DD HH:mm', when I actualy want it to be in that format: 'YYYY/MM/DD HH:mm:ss' (the secondes dosen't apper).
Does anyone know why, and what should I do in order to fix this?

Here is the code I using:

con = new SqlConnection("....");
String startAt = "20100413 11:05:28";
String endAt = "20100414 11:05:28";
...
con.Open();//open the connection, in order to get access to the database
SqlCommand command = new SqlCommand("insert into ProcessData (Start_At, End_At) values('" +  startAt + "','" + endAt + "')", con);
command.ExecuteNonQuery();//execute the 'insert' query.
con.Close();

Many thanks

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about datetime-format