Solved

casting error handling database info

Posted on 2007-04-09
1
358 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The viewer will learn how to synchronize PHP projects with a remote server 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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now