How to avoid this kind of exception?

I have an sqlite database, and a table, in which i have a column PIN as a TEXT, and it's empty. when i'm getting it from the database, and trying to convert into a string it brings me an exception, When casting a number the value must be less then infinity...what is the reason?


In databases like sqlite, empty strings and null are two different things. It looks like you may be trying to cast your PIN to an int, or some other integer type. If the PIN field is null or DBNull, this cast will fail, giving the exception you listed. To further complicate things, null != DBNull.Value, which is what your database query is likely returning.

To check for this, you need to check the PIN field against DBNull.Value and cast only after you've checked.

See: DBNull Class

See: A similar SO question

Need Your Help

Copying Mat to raw array in OpenCV with Java? (Getting “multiple of channels count” error)

java scala opencv image-processing

I'm trying to load an image in Scala using OpenCV with the Java bindings. After loading the image, I'd like to convert it to a traditional Scala Array[Float].

Hide bootstrap panels

javascript jquery twitter-bootstrap

I have panel content (not an accordian) setup to be hidden on page load. When a user clicks on one of the tabs, a "hidden" class is removed thus showing the panel content. Then I want to hide the c...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.