Specified cast is not valid?

Posted on 2011-10-28
Medium Priority
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
  • 2
  • 2
LVL 22

Accepted Solution

p_davis earned 1500 total points
ID: 37047068
a char is actually an int if you wanted to tho' you could data["TranC"].ToString() == "A";

Author Comment

ID: 37047529
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

ID: 37047547
did you try the

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

Author Closing Comment

ID: 37047637
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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