|
-
May 15th, 2002, 03:20 AM
#1
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?
-
May 15th, 2002, 08:32 AM
#2
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
Jared
-
May 15th, 2002, 11:22 AM
#3
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
-
May 15th, 2002, 12:27 PM
#4
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
Jared
-
June 4th, 2002, 08:27 PM
#5
Re: Re: C# & SQL Server DateTime formats
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|