Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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???
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:50 AM.


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