"FormatException was unhandled" Input string was not in a correct format.

Hi !

Here I am trying to write a function that returns me value based on the following condition...

IF

Variable is NULL return me DBNull.Value

ELSE

Convert Variable into DataType whose DataTypeCode has been provided to me as a parameter of function.

Now while converting a variable into required DataType an exception is thrown "FormatException was unhandled". Input string was not in a correct format.

How do I resolve this error please help.

Here is my code...

public object ReturnDBNullOrRequiredDatatype(object IsThisObjectANull, TypeCode DataTypeCode)
 
{
     if (Convert.IsDBNull(IsThisObjectANull) == true)
                return DBNull.Value;
    else
              return Convert.ChangeType(IsThisObjectANull, DataTypeCode);
 
}
 

Thanks in Advance

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr><br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong><font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • You can enable syntax highlighting of source code with the following tags: <c>, <cpp>, <csharp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <sql>, <tsql>, <vbnet>, <xml>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Lines and paragraphs break automatically.

More information about formatting options