Wrapping a date field so precision is not lost?

  • Thread starter Thread starter SenseiHitokiri
  • Start date Start date
S

SenseiHitokiri

I learned today that an insert statement I am generating out of a
DataSet which gets populated straight from SqlDataReaders is not giving
me the same precision that it is stored in the database with.

Table 1 (Origin table)
Nov 8 2006 5:19:10:617PM

is being stored as

Table 2 (Destination Table)
Nov 8 2006 5:19:10:000PM

because the insert looks like

SET [CREATE_DATE]='11/8/2006 5:19:10 PM'

When I am reading from Table 1 into the Dataset and displaying it in a
DataGridView it shows up as 11/8/2006 5:19 PM. So then when I try to
write an insert string for a SqlCommand object I just try to append the
field from the DataSet. The insert string is generated like this
[CREATE_DATE]='11/8/2006 5:19:10 PM'. Is there a way to get my dataset
to handle this precision on it's own? I don't want to write methods
that will parse the string for the word date and I don't want to create
a library of table columns because that may run into it's own problems.
So basically I'm left with two options in my eyes: Figure out how to
get the dataset to realize the columns precision or Write a method to
determine the column's type and then apply the proper formatting to the
string.
 
I learned today that an insert statement I am generating out of a
DataSet which gets populated straight from SqlDataReaders is not giving
me the same precision that it is stored in the database with.

Table 1 (Origin table)
Nov 8 2006 5:19:10:617PM

is being stored as

Table 2 (Destination Table)
Nov 8 2006 5:19:10:000PM

because the insert looks like

SET [CREATE_DATE]='11/8/2006 5:19:10 PM'

When I am reading from Table 1 into the Dataset and displaying it in a
DataGridView it shows up as 11/8/2006 5:19 PM. So then when I try to
write an insert string for a SqlCommand object I just try to append the
field from the DataSet. The insert string is generated like this
[CREATE_DATE]='11/8/2006 5:19:10 PM'. Is there a way to get my dataset
to handle this precision on it's own? I don't want to write methods
that will parse the string for the word date and I don't want to create
a library of table columns because that may run into it's own problems.
So basically I'm left with two options in my eyes: Figure out how to
get the dataset to realize the columns precision or Write a method to
determine the column's type and then apply the proper formatting to the
string.

There's a difference between the storage of datetime values in the
..NET framework and SQL Server. Read these articles for some details of
the difference and some possible workarous:

http://www.velocityreviews.com/forums/t111968-datetime-problem.html

http://www.eggheadcafe.com/articles/20021111.asp

http://blogs.wdevs.com/angelos/archive/2005/06/02/3660.aspx
 
Rad said:
I learned today that an insert statement I am generating out of a
DataSet which gets populated straight from SqlDataReaders is not giving
me the same precision that it is stored in the database with.

Table 1 (Origin table)
Nov 8 2006 5:19:10:617PM

is being stored as

Table 2 (Destination Table)
Nov 8 2006 5:19:10:000PM

because the insert looks like

SET [CREATE_DATE]='11/8/2006 5:19:10 PM'

When I am reading from Table 1 into the Dataset and displaying it in a
DataGridView it shows up as 11/8/2006 5:19 PM. So then when I try to
write an insert string for a SqlCommand object I just try to append the
field from the DataSet. The insert string is generated like this
[CREATE_DATE]='11/8/2006 5:19:10 PM'. Is there a way to get my dataset
to handle this precision on it's own? I don't want to write methods
that will parse the string for the word date and I don't want to create
a library of table columns because that may run into it's own problems.
So basically I'm left with two options in my eyes: Figure out how to
get the dataset to realize the columns precision or Write a method to
determine the column's type and then apply the proper formatting to the
string.

There's a difference between the storage of datetime values in the
.NET framework and SQL Server. Read these articles for some details of
the difference and some possible workarous:

http://www.velocityreviews.com/forums/t111968-datetime-problem.html

http://www.eggheadcafe.com/articles/20021111.asp

http://blogs.wdevs.com/angelos/archive/2005/06/02/3660.aspx

Thanks that really helped me to understand the difference between the
two types but it leaves me with this question which is half-aimed at
the world and half-aimed at Microsoft. Why would a dataset fill itself
with a datatype that isn't the same as the table's especially when I'm
using Microsoft SQL Server. I mean it's looking like my options are
either to create some new calculated field in the table ( which I don't
actually have permission to do since it would be modifying some clossal
beast I'd rather not modify haha ) or creating a filter method that
will append a SQL convert function call to the select column name.
Since doing this would quite frankly "suck" I was hoping there would be
some way of telling the dataset to use the SqlDateTime thus persisting
the precision.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top