473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Exception Number in VS2005

How to I get the Exception Number (code) for a database related error?
I get the following error and I need to catch it to display a custom message.

System.InvalidCastException: Unable to cast object of type 'System.DBNull'
to type 'System.Byte
Oct 3 '08 #1
2 1492
Never mind; i've figured it out as:

ex is System.InvalidCastException

"Rick" wrote:
How to I get the Exception Number (code) for a database related error?
I get the following error and I need to catch it to display a custom message.

System.InvalidCastException: Unable to cast object of type 'System.DBNull'
to type 'System.Byte
Oct 3 '08 #2
On Oct 3, 2:04 pm, Rick <R...@discussions.microsoft.comwrote:
How to I get the Exception Number (code) for a database related error?
I get the following error and I need to catch it to display a custom message.

System.InvalidCastException: Unable to cast object of type 'System.DBNull'
to type 'System.Byte
Hi,

There is no such a thing, You can know the problem by the Exception
Type and the Message.
In your case it;s clearly a casting issue

Tip:
try to use coalesce in the sql query
Oct 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: carbon_dragon | last post by:
The application is a console app, though it does have a temporary windows form console, which is fairly complicated and which was developed in VS2003. I installed VS2005 on an XP OS and tried to...
6
by: aioe.cjb.net | last post by:
So, I was planning on ridding my VS2005 solution of all warnings, but the ones sounding "The variable 'ex' is declared but never used" in catch-blocks, are causing a headache. I have several...
6
by: semedao | last post by:
Hi All, I had working code that made custom serialization on objects that inherit from queue in the inherited queue I create my own GetObjectData: public void GetObjectData(SerializationInfo info,...
4
by: Michael Bray | last post by:
I'm converting a project from VS2003 to VS2005, and one of the most common errors that I'm getting is on my try/catch blocks, where I used to do: try { ... } catch (exception &e) { ... } ...
2
by: John | last post by:
Hi I am looking for an exception handler that can handle all unhanded exceptions in my vb2005 app and also email the exception log to myself. There is one here...
7
by: Boris | last post by:
I have a mixed DLL (a managed DLL in C++ calling functions in other unmanaged DLLs) which I can build successfully in Visual Studio 2005 but can't reference as I get then immediately the error: ...
6
by: Kristijan Marin | last post by:
Hi, Can please anyone tell me why do i get only the first method in which the exception was thrown and not the line that triggered the exception ? I don't know if I set something in VS2005 wrong...
7
by: Pixel.to.life | last post by:
Gurus, Another question on one of the coveted Microsoft products: JIT debugger with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for...
0
by: Pixel.to.life | last post by:
Gurus, Another question on one of the coveted Microsoft products: JIT debugger with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.