473,326 Members | 2,438 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,326 software developers and data experts.

GetType of custom Property set to nothing

I want to return the proper Null to the SQL Database if my property is
nothing
Also I thought about creating a function so I don't have to put so many if
statement for each property for each classes etc.
However if I call ReturnValue(myClass.CompanyName) and CompanyName is
Nothing then it crash where it shoud return SqlTypes.SqlString.Null
Private _CompanyName As String
<ComponentModel.Browsable(True), ComponentModel.Description("CompanyName"),
ComponentModel.ReadOnly(False)> _
Public Property CompanyName() As String Implements iCompany.CompanyName
Get
Return _CompanyName
End Get

Set(ByVal Value As String)
Me._CompanyName = Value
End Set
End Property

Function ReturnValue(ByVal thisObject As Object) As Object
Try
If IsNothing(thisObject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the type
Select Case thisObject.GetType.ToString
Case GetType(System.String).ToString
Return SqlTypes.SqlString.Null
Case GetType(System.Boolean).ToString
Return SqlTypes.SqlBoolean.Null
Case Else
Return SqlTypes.SqlString.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlString.Null
End Try
End Function

Thanks for the help

Nicolas
Mar 28 '06 #1
1 1708
Function ReturnValue(ByVal thisObject As Object) As Object
Try
If IsNothing(thisObject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the
type
Select Case thisObject.GetType.ToString
Case GetType(System.String).ToString
Return SqlTypes.SqlString.Null
Case GetType(System.Boolean).ToString
Return SqlTypes.SqlBoolean.Null
Case Else
Return SqlTypes.SqlString.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlString.Null
End Try
End Function

Nick,

If you want to return null if the object is nothing, try:

Function ReturnValue(ByVal Value As Object) As Object
If Value Is Nothing
Return DBNull.Value
Else
Return Value
End If
End Function
HTH,
Mythran

Mar 28 '06 #2

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

Similar topics

7
by: Steve Jorgensen | last post by:
Here is some code to generate code for raising and getting information about custom errors in an application. Executing the GenerateXyzErrDefs procedure generates the code. <tblXyzError>...
19
by: laurenq uantrell | last post by:
I'm using Access 2K. I'm hoping someone can tell me which method performs faster- (currently I'm using a mix of both methods) a.) creating custom properties and then calling functions to set and...
4
by: RichB | last post by:
Hello, The .NET application I have just installed at a client web site is throwing a strange error. At first the applications works without any problems, but after 10 mins or so Access denied...
6
by: Steve Amey | last post by:
Hi all I want to be able to throw a custom error up the call stack. I have looked around and it seems as though it's possible, but I can't get it to work :o( Below is some sample code. ...
1
by: Stu | last post by:
Hi, Im using vis studio 2003 and I think wse is out of the question as clients could be using java which doesnt support it. So I managed to find some code which allows you to develop a custom...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
9
by: Kirk | last post by:
I have successfully, implemented a custom Membership Provider to a SQL 2000 table, however, I am having problems doing the same with a Profile Provider. As I understand it, the steps for both of...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.