Solved

casting error handling database info

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

744 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

10 Experts available now in Live!

Get 1:1 Help Now