Specified cast is not valid?

Posted on 2011-10-28
Last Modified: 2012-05-12
This is my statement:  
if ((byte)data["TranC"] == 'A')

Open in new window

The field is defined as "char" in a Firebird table. How should I cast this?
Question by:rmmarsh
    LVL 22

    Accepted Solution

    a char is actually an int if you wanted to tho' you could data["TranC"].ToString() == "A";

    Author Comment

    I did it without the cast, and I did it with the "int" cast... either way, I get the error "Specified cast is not valid".

    And then I did this:  if (int.Parse(data["TranC"].ToString()) == 'A')

    and the CLR tells me the input string was not in the correct format!

    Any other suggestions?
    LVL 22

    Expert Comment

    did you try the

    data["TranC"].ToString() == "A";//?

    Author Closing Comment

    I'm going to give you the points because you were very close... this is what I wound up doing:

     shipping = uint.Parse(data["Shipping"].ToString());

    And it appears to be working... thank you for the time...

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 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

    16 Experts available now in Live!

    Get 1:1 Help Now