473,396 Members | 1,832 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,396 software developers and data experts.

error trapping when binding to custom class

zak
I have a custom class object which I'd like bound to text boxes etc on the form. All properties of the class look something like this

<System.ComponentModel.Description("Get/Set value associated with Phone column")>
Public Property Phone() As Strin
Ge
Me.CheckDisposed(
If (m_IsNullPhone = True) The
Throw New System.Data.StrongTypingException("Cannot get value because it is DBNull", Nothing
End I
Return m_Phon
End Ge
Set(ByVal Value As String
Me.CheckDisposed(
m_Phone = valu
m_Changed = Tru
m_IsNullPhone = Fals
End Se
End Propert

Whe I bind this property to a text box I get this error just after the form load
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in system.dl

Additional information: Property accessor 'Phone' on object 'PPSS.Person' threw the following exception:'Cannot get value because it is DBNull

There seams to be no obvious way to intercept this error using the Binding object but can only catch it by using a high level error trap. The dataset object seams to handle this situation without raising an error so i guess there must be a way to do this.

Regard
Nov 20 '05 #1
2 1974
Hi,

Instead of throwing an error if the phone isn't set why dont you make
the user set it when he creates a new one of your custom classes. That way
you dont have to worry about it being null.

Public Sub New(byval Phone as string)
m_phone = phone
End sub

Ken
----------------------
"zak" <Zl*****@bcs.org.uk> wrote in message
news:37**********************************@microsof t.com...
I have a custom class object which I'd like bound to text boxes etc on the
form. All properties of the class look something like this:

<System.ComponentModel.Description("Get/Set value associated with Phone
column")> _
Public Property Phone() As String
Get
Me.CheckDisposed()
If (m_IsNullPhone = True) Then
Throw New System.Data.StrongTypingException("Cannot get
value because it is DBNull", Nothing)
End If
Return m_Phone
End Get
Set(ByVal Value As String)
Me.CheckDisposed()
m_Phone = value
m_Changed = True
m_IsNullPhone = False
End Set
End Property

Whe I bind this property to a text box I get this error just after the
form load:
An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in system.dll

Additional information: Property accessor 'Phone' on object 'PPSS.Person'
threw the following exception:'Cannot get value because it is DBNull'

There seams to be no obvious way to intercept this error using the Binding
object but can only catch it by using a high level error trap. The dataset
object seams to handle this situation without raising an error so i guess
there must be a way to do this.

Regards

Nov 20 '05 #2
zak
I can't do that.
My values come from the database and all my classes support IsPropertyNull (i.e IsPhoneNull) properties and SetPropertyNull (i.e. SetPhoneNull) methods. Strongly typed datasets seam to handle this nicelly but I just don't see how. I think inspection of MSIL is next (not that I wanted to go there).

Thanks for the effort.
Nov 20 '05 #3

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

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
3
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event...
1
by: Antero | last post by:
I'm desperate! :-/. I'm desperately trying to bind to objects together to share same data and to display it in a windows forms. I'm trying to bind an custom object to custom control property. I...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
10
by: =?Utf-8?B?SmFjayBTbWl0aA==?= | last post by:
Hello, I have a solution that contains a C# application that is installed and runs as a service. The solution also contains several DLLs, some of which are C# assemblies and some are C++ DLLs. ...
9
by: =?Utf-8?B?VGVycnk=?= | last post by:
Think it is great the way that you can set up a datsource, value member, and display member for a combobox, and map a 'code' to a 'description' and back again by binding the combobox to a...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.