Incorrect times returned by ADO

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I get a datetime value that INCLUDES fractions of seconds from a
sqldatareader. SqlDataReader.GetDateTime(Index) returns only dd/mm/yy
hh:mm:ss. So when I use it to create an insert statement to transfer the data
to another database, the value inserted often includes a rounding error!
 
Hi Richard,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you cannot get millisecond using
SqlDataReader from the database. If there is any misunderstanding, please
feel free to let me know.

Based on my research, SqlDataReader.GetDateTime will get the millisecond
from the database. Here is a code snippet that displays the Milliosecond on
the form.

SqlCommand cmd = new SqlCommand("SELECT * FROM Table1",
this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
DateTime dt = sdr.GetDateTime(1);
this.Text = dt.Millisecond.ToString();
sdr.Close();
this.sqlConnection1.Close();

Since in SQL Server, DateTime type represents data from January 1, 1753
through December 31, 9999, to an accuracy of one three-hundredth of a
second (equivalent to 3.33 milliseconds or 0.00333 seconds), values are
rounded to increments of .000, .003, or .007 seconds. So the rounding error
might occur when the data was inserted to the original database. However,
this is by design.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top