Solved

casting error handling database info

Posted on 2007-04-09
1
360 Views
Last Modified: 2013-11-26
I am having a problem with this error:  Specified cast is not valid.  This error has been generated from this line of code:  Recurrence.UtcOffset = (TDataSet.Tables(0).Rows(i).Item("UtcOffset")).  Recurrence.UtcOffset is a timespan value.  the TDataSet.Tables(0).Rows(i).Item("UtcOffset")) value coming in is -300.  The database field is set to accept int values.  The database is a copy of an example database for appointment scheduling through WebScheduleInfo Infragistic NetAdvantage products.  The procedure needed to be used is  Private Sub FetchRecurrences(ByVal context As FetchRecurrencesContext) is for getting the values from the database and using the values for handling the display of the recurrence value/purposes in the webmonthview, webweekview, or webdayview and handle the recurrence of a given appointment/appointments.  The actual question is how do I handle the error.
0
Comment
Question by:TroyCrowe
1 Comment
 
LVL 10

Accepted Solution

by:
tpwells earned 250 total points
ID: 18881511
To handle the error you can place the call in a Try..Catch handler

Try
 Recurrence.UtcOffset = (TDataSet.Tables(0).Rows(i).Item("UtcOffset"))
Catch ex as Exception
  'Preform some code to handle the error
End Try

Part of there error here is that type Integer can not be converted directly to type TimeSpan. What does the -300 represent? seconds, minutes, hours, days. If you know that then you can use the TimeSpan contructor to create the needed TimeSpan Object.

Dim ts as New TimeSpan(Ticks)
Dim ts as New TimeSpan(Hours, Minutes, Seconds)
Dim ts as New TimeSpan(Days, Hours, Minutes, Seconds)
Dim ts as New TimeSpan(Days, Hours, Minutes, Seconds, Milliseconds)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Capture logon name 13 73
Where did System.Data.Objects go? 2 28
VB.NET 2008 - SQL Timeout 9 24
JSON  parse help 7 27
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

803 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