Solved

How to save back a dataset containing TimeSpan fields?

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DMV Script to find how many times statistics are utilized 2 30
sql server query 9 28
Section based report in SSRS 14 36
Group ordersum by orderdate 3 23
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

710 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