Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 30th, 2009, 05:54 PM
Authorized User
 
Join Date: Aug 2008
Location: , WA, .
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default Dataset not rounding DateTime correctly

My application takes an XML file and loads it into a dataset to do some manipulations before storing it in a SQL Server. Each XML entry has a datetime child node that goes down to the nanosecond. The dataset will round that to the millisecond, example:
2009-01-26 12:00:27.131159540-0800 changes to
2009-01-26 12:00:27.130

This is fine. However, there is a rare case that occurs as such:
2009-01-26 12:00:27.198485020-0800 changes to
2009-01-26 12:00:27.1100

So, in this specific instance, the example of the rare case would normally be organized after the first example shown, but now that the dataset rounded as such it will be the opposite order. I need to have the original order kept.

Is this a bug with the Dataset or is there something I'm missing.

Here is how the code looks when it is loaded:

Code:
protectedvirtualvoid Load()
{
_dataset.EnforceConstraints = false;
_dataset.ReadXmlSchema(_XSDLocation);
_dataset.ReadXml(_name, XmlReadMode.IgnoreSchema);
}
  #2 (permalink)  
Old January 31st, 2009, 02:02 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

No, SQL Server does *NOT* round "to the millisecond".

http://msdn.microsoft.com/en-us/libr...7(SQL.80).aspx

It rounds to the nearest integer multiple of 3.33 milliseconds.
As that page says, "Values are rounded to increments of .000, .003, or .007 seconds..." So you will never see a value such as xxx.814 -- it would have to be either xxx.813 or xxx.817

Having said all that...

I sure don't see why x.198 would get rounded to x.110

Sounds like a bug in SQL Server and/or the driver.

But in any case, it doesn't sound to me like this is ever going to be accurate enough for your purposes. So I hate to say it, but I think you are going to have to create your own pseudo-datatype to hold you dates and times as accurately as you need them.

I would suggest that you might want to just keep them as strings (VARCHAR/NVARCHAR) if they indeed have the format you show:
2009-01-26 12:00:27.198485020-0800
presumably if you just lopped off the "-0800" you would have values that would always sort correctly, to whatever the recorded accuracy you have. [Even the "-0800" wouldn't interfere unless the number of digits after the decimal point is variable.]

Hmmmm???


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding JasperGIS Beginning VB 6 1 December 14th, 2005 03:09 PM
Rounding kilika SQL Server 2000 4 June 1st, 2005 03:36 PM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM
Dataset does not get sorted correctly Imar ADO.NET 2 December 29th, 2003 04:49 PM
Rounding Droopy Classic ASP Basics 3 August 14th, 2003 08:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.