469,635 Members | 1,966 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

no millisecond from Sqldatetime to System.Datetime

Hi to all,
I have a trouble with datetime...now I explain..
I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005.
I tried 3 methods ...in the first two I never was able to get the Millisecond from datacolumn.
I explain the methods...

1) I created a Datatable that contain the column... then I fill a datarow with the current value. The system automatically
converts the Sqldatetime in System.Datetime but it isn't able to memorize the millisecond.
In sql table they are 807 but in datarow the are equal to zero.

Then...
2) I used this lines..
SqlDataReader reader = command.ExecuteReader();
while(reader.Read() == true)
{
SqlDatetime p=reader.GetDateTime(0);
}

but The system cut again the milliseconds...
Then i Thought that it's a trouble about the convertion beetwen SqlDatetime--->System.Datetime so i tried that:

3)SqlDataReader reader = command.ExecuteReader();
while(reader.Read() == true)
{
SqlDatetime p=reader.GetSqlDateTime(0);
}
now it work well!!!! The milliseconds are valorized correctly...

Now the questions :)
1)My theretical question : for me it's absurd that System.Datetime not store the milliseconds from sql because
in the System.Datetime the Time values are measured in 100-nanosecond units while the Sqldatetime has an accuracy
of 3.33 milliseconds...I suppose that system.Datetime would contain the millisecond values of SqlDatetime without problems...

2)My Pratical Question: I need to use a Datarow because the table has many columns... but I can't because the
system converts automatically the Sqldatetime (from the Datetime Column) in System.Datetime and not memorize the milliseconds for that column...
Any ideas for that?
Thank you very much.
Oct 29 '09 #1
0 2439

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by damon.f | last post: by
1 post views Thread by poppy | last post: by
1 post views Thread by Paperback Writer | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.