Click to See Complete Forum and Search --> : C# & SQL Server DateTime formats


Gabro
May 15th, 2002, 03:20 AM
my problem goes likes this:
whenever a user creates a record (application is coded in C#), the program should automatically insert the current date into the SQL Server DB together with the record. the field for the date in the DB is defined as datetime. However, I have problems coming up with the appropriate c# code to insert the time into the DB. I do not wish to change the data type to string and have the date converted to a string first b4 I store it in the DB. Help is greatly appreciated.

one other thing. SQL Server would automatically insert the time if I manually keyed in a date in the DB. Is there anyway I can bypass that? I'm not interested in the time at all? Anyway, I'm using SQL Server 7. Would SQL Server 2000 provide a bettter fix for my problem?

jparsons
May 15th, 2002, 08:32 AM
Try the System.Data.SqlClient.SqlDataReader. This class has the ability to convert from C# DateTime and SQL Date times. It can also convert I believe any SQL type to any C# type.

Jared Parsons

Gabro
May 15th, 2002, 11:22 AM
i don't quite get wad u mean. could you elaborate your point further? perhaps you could include some source code.
thanks

jparsons
May 15th, 2002, 12:27 PM
I'm still slightly confused about your first post. ARe you simply trying to convert a C# dateTime into a Sql ready format? If so then this shoudl work.


public SqlDateTime getDateTime()
{
return new SqlDateTime(DateTime.Now);
}





Jared Parsons

Gabro
June 4th, 2002, 08:27 PM
Originally posted by jparsons
I'm still slightly confused about your first post. ARe you simply trying to convert a C# dateTime into a Sql ready format? If so then this shoudl work.


public SqlDateTime getDateTime()
{
return new SqlDateTime(DateTime.Now);
}





Jared Parsons

exactly wad i wanted!
thx for everything.