Solved

How to save back a dataset containing TimeSpan fields?

Posted on 2009-07-10
4
1,149 Views
Last Modified: 2012-06-22
Im reading a database table (Sql Server) which has some timespan fields, saved as BigInt (the Ticks value). I'm loading a typed dataset that has these fields defined as TimeSpan using EntLib Database.LoadDataset (beeing nothing more than a wrapper around DataAdapter.Fill). Data is filled just fine and the BigInt fields converted to TimeSpan...

After editing, I try to save back the Dataset with a Database.UpdateDataset (wrapper to DataAdapter.Update) but fail with System.InvalidCastException - Failed to convert parameter value from a TimeSpan to a Int64.

Anyone has an idea how to close the loop?
0
Comment
Question by:simonstre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:pepepaco
ID: 24827899
cast it as double, it should works, otherwize use unsigned int 64 UInt64

or you can also edit the dataset and change the field type to one of those (double or UInt64)
regards.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24828483
>>System.InvalidCastException - Failed to convert parameter value from a TimeSpan to a Int64.<<
There is something else going on.  BigInt is exactly the same as Int64.  Please first verify that it is in fact bigint and if it is then post your code that gets the data.
0
 
LVL 1

Accepted Solution

by:
simonstre earned 0 total points
ID: 25017648
I have found that there is a convertion from Int64 to TimeSpan but no convertion exists from Timespan to Int64... I ended up saving the time value as Double (float in sql) representing the number of hour since 00:00. I have to manually convert to TimeSpan using TimeSpan.FromHours.
0
 
LVL 4

Expert Comment

by:pepepaco
ID: 25018695
the conclusion is very similar to my answer, so  please give me some points :)

just in case it was helpful..

regards.

0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question