C# & SQL Server DateTime formats
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?
Re: C# & SQL Server DateTime formats
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
Re: C# & SQL Server DateTime formats
i don't quite get wad u mean. could you elaborate your point further? perhaps you could include some source code.
thanks
Re: C# & SQL Server DateTime formats
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
Re: Re: C# & SQL Server DateTime formats
Quote:
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.