Matthias,
DateTime can represent information with greater accuracy than T-SQL's
datetime type (which is accurate to (1/300) second), so you are probably
seeing the effect of rounding or truncation. You should consider
choosing the SqlTypes SqlDateTime data type for your application instead
of .NET DateTime. The SqlTypes class included in the framework
precisely for this purpose - to improve compatibility with SQL Server
data types.
SK
[quoted text, click to view] Matthias S. wrote:
> Hi there,
>
> I'm writing a C# application and using a C#Express Beta2 and
> SQLExpress Beta2:
>
> I've created an object (say 'Human') which I persist to a SQL DB
> table. Human has a DateOfBirth property of the (.Net) type DateTime.
> The apropriate field in the table is of SQL type DateTime. Now I
> create an instance of my Human and set the DateOfBirth to yesterday
> using the following code:
>
> Human Human1 = new Human();
> Human1.DateOfBirth = new DateTime.Now.Substract(new TimeSpan(1, 0, 0,
> 0));
>
> Then that I persist my you Human to the database. After that I create
> a new instance of my Human (Human2) and read it's property-values from
> the database, like:
>
> if(Human1.DateOfBirth == Human2.DateOfBirth) {
> // this code is never reached :)
> }
>
> Comparing Human1's DateOfBirth with Human2's I do not get the expected
> result as the two DateTime objects return the same Date and Time, but
> looking at the DateTime.Tick property I see some fractional
> differences :).
>
> How do you handle this? Thanks in advance.
>
> Matthias
>
Oops - I forgot where I was posting. For SQL Server 2005 questions, you
might wish to read and post to the semi-private newsgroups that have
been established for the beta version of that product
(
http://communities.microsoft.com/newsgroups/default.asp?icp=sqlserver2005&slcid=us).
SK
[quoted text, click to view] Matthias S. wrote:
> Hi there,
>
> I'm writing a C# application and using a C#Express Beta2 and
> SQLExpress Beta2:
>
> I've created an object (say 'Human') which I persist to a SQL DB
> table. Human has a DateOfBirth property of the (.Net) type DateTime.
> The apropriate field in the table is of SQL type DateTime. Now I
> create an instance of my Human and set the DateOfBirth to yesterday
> using the following code:
>
> Human Human1 = new Human();
> Human1.DateOfBirth = new DateTime.Now.Substract(new TimeSpan(1, 0, 0,
> 0));
>
> Then that I persist my you Human to the database. After that I create
> a new instance of my Human (Human2) and read it's property-values from
> the database, like:
>
> if(Human1.DateOfBirth == Human2.DateOfBirth) {
> // this code is never reached :)
> }
>
> Comparing Human1's DateOfBirth with Human2's I do not get the expected
> result as the two DateTime objects return the same Date and Time, but
> looking at the DateTime.Tick property I see some fractional
> differences :).
>
> How do you handle this? Thanks in advance.
>
> Matthias
>
Hi there,
I'm writing a C# application and using a C#Express Beta2 and SQLExpress
Beta2:
I've created an object (say 'Human') which I persist to a SQL DB table.
Human has a DateOfBirth property of the (.Net) type DateTime. The
apropriate field in the table is of SQL type DateTime. Now I create an
instance of my Human and set the DateOfBirth to yesterday using the
following code:
Human Human1 = new Human();
Human1.DateOfBirth = new DateTime.Now.Substract(new TimeSpan(1, 0, 0, 0));
Then that I persist my you Human to the database. After that I create a
new instance of my Human (Human2) and read it's property-values from the
database, like:
if(Human1.DateOfBirth == Human2.DateOfBirth) {
// this code is never reached :)
}
Comparing Human1's DateOfBirth with Human2's I do not get the expected
result as the two DateTime objects return the same Date and Time, but
looking at the DateTime.Tick property I see some fractional differences :).
How do you handle this? Thanks in advance.
Matthias
Don't see what you're looking for? Try a search.