Solved

How to save back a dataset containing TimeSpan fields?

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

821 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