question
-
i need example in C# + SQL SERVER i want to insert into the DB date and time for example 12/15/2005 and time 10:05 AM how can i define the sqlcommand and lets say in the DB table test i have the colum d as datetime and t as timestamp eyalso
-
string ins = "insert into table values('" + "2005.12.15 10:05 AM" + "')" SqlDataAdapter da= new SqlDataAdapter (ins,SqlConnection); replace DateTime with varchar ur column in ur table Regards -- modified at 4:51 Thursday 15th December, 2005
seferi wrote:
replace DateTime with varchar ur column in ur table
Thats easily the worst advice ive read here! DONT use varchar to store a date! Also, to THE OP - Timestamp is a special type of binary column, and is not used to store time as the name does imply. To store date and time just create a Date column, which will store a date and time perfectly. Remember to use parameterized queries (for dates especially as the command will take care of inserting the date correctly)
-
i need example in C# + SQL SERVER i want to insert into the DB date and time for example 12/15/2005 and time 10:05 AM how can i define the sqlcommand and lets say in the DB table test i have the colum d as datetime and t as timestamp eyalso
Instead of storing a DateTime variable store a long (8 byte). convert the DateTime variable to a long by: DateTime A = ; long B = DateTime.Ticks; in order to convert the long number back to DateTime do: DateTime AA = DateTime.MinValue + TimeSpan.FromTicks(B); Enjoy Gilad.