Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

casting error handling database info

Posted on 2007-04-09
1
Medium Priority
?
366 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

618 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