Solved

How to save back a dataset containing TimeSpan fields?

Posted on 2009-07-10
4
1,131 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
  • 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now