Solved

How to save back a dataset containing TimeSpan fields?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 extract information from SQL Server on Database, Connection and Server properties

947 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

20 Experts available now in Live!

Get 1:1 Help Now