Re: Typed dataset: Time only data in SQL dateTime Field
- From: "Stephany Young" <noone@localhost>
- Date: Tue, 23 Jan 2007 13:55:00 +1300
I think that you're still missing the point Jeff.
The point is that, while inserting a value into a Jet database and then
viewing the data in MS Access will give you the results you are observing,
if you view the data via any aother 'mechanism' then you NOT observe that
same behaviour.
There is code built into MS Access that, for a Jet Date/Time data type,
basically says "Aha! I know all about a value where the integral part is 0
or -0 (#12/30/1899#) so I will hide the date part from you and only show you
the time part unless you instruct me otherwise".
That behaviour in MS Access may be all well and good for a column where you
are only interested in the time part, but it will also behave in the same
way for a column containing birth dates and the birth date for a particular
person happens to be December 30 1899 (sure that would make them 107). MS
Access, unless instructed otherwise, will still hide the date part from you
because it doesn't know the difference between an actual date of
#12/30/1899# and a value where you have only inserted the time part.
When you migrate the data from Jet to SQL Server then you will find that SQL
Server has no such date part suppressing mechanism by default, and even if
it did, it would work on the date 1900-01-01 and not 1899-12-30. That is
because 0 or -0 represents a different date on SQL Server than it does in
Jet.
When, in a .NET environment, you retrieve the value from either Jet or SQL
Server, you are, whether you realise it or not, populating an instance of a
..NET DateTime structure. If you only want to see the time part then you MUST
explicitly suppress the date part. There are a number of methods of the
DateTime structure that you can use to do this.
If you only use the database datetime column for storage retrieval purposes
and NEVER (I repeat NEVER) do any maths on the values or sort the column
then what the date part actually is is irrevalent and can be any old date
that is valid for the environment (#0100/01/01# to #9999/12/31# for Jet or
'1753-01-01' to '9999-12-31' for SQL Server).
The moment that you need to do any maths on the values or sort the column
then the date parts MUST be values that are contextually correct for
whatever operation you are applying.
"JeffDotNet" <JeffDotNet@xxxxxxxxxxxxxxxxx> wrote in message
news:5244D31B-6A43-4CE6-A4E3-E1829C06CBC7@xxxxxxxxxxxxxxxx
Thanks Wen and Stephany,
This is indeed what I was looking for.
Dim SqlTimeOnly As Date = #12/30/1899#
SqlTimeOnly = SqlTimeOnly.Add(MyTime.TimeOfDay)
MyTableAdapter.Insert(sqlTimeOnly,yada,yada,yada)
This does in fact produce the outcome I wanted. When displaying the table
after insert only the time appears.
Thanks Again,
Jeff
"WenYuan Wang" wrote:
Hi Jeff,
I agree with Stephany. The DateTime filed always contains both date and
time parts. I'm afraid that it is not possible for us to only insert time
into DateTime type column. SQL Server inserts midnight (00:00:00) when
time
information is missing, and 1900-01-01 when date information is missing.
But, under my test, in SQL 2000 if we set the date information to
"1899-12-30" SQL database will only display the time part of the field.
This is similar that you directly insert time into table by SQL Server
Enterprise Manager. I think maybe this is what you want.
For example:
Insert TableName into ([c1,c2]) values (1,' 1899-12-30 18:00')
In SQL database, the table will only show the time part of the field.
If you don't want to insert the day part into table, we suggest you can
set
the date information to "1899-12-30".
I think this is the workaround to your issue.
Hope this will help.
Sincerely,
Wen Yuan
.
- References:
- Re: Typed dataset: Time only data in SQL dateTime Field
- From: Stephany Young
- Re: Typed dataset: Time only data in SQL dateTime Field
- From: JeffDotNet
- Re: Typed dataset: Time only data in SQL dateTime Field
- From: WenYuan Wang
- Re: Typed dataset: Time only data in SQL dateTime Field
- From: JeffDotNet
- Re: Typed dataset: Time only data in SQL dateTime Field
- Prev by Date: Re: Queries to an Access db from vs2005
- Next by Date: Leftover Connections in Connection Pool (connection leak)
- Previous by thread: Re: Typed dataset: Time only data in SQL dateTime Field
- Next by thread: RE: Typed dataset: Time only data in SQL dateTime Field
- Index(es):
Relevant Pages
|