Solved

casting error handling database info

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

717 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