473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(myC lass.CompanyNam e) and CompanyName is
Nothing then it crash where it shoud return SqlTypes.SqlStr ing.Null
Private _CompanyName As String
<ComponentModel .Browsable(True ), ComponentModel. Description("Co mpanyName"),
ComponentModel. ReadOnly(False) > _
Public Property CompanyName() As String Implements iCompany.Compan yName
Get
Return _CompanyName
End Get

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

Function ReturnValue(ByV al thisObject As Object) As Object
Try
If IsNothing(thisO bject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the type
Select Case thisObject.GetT ype.ToString
Case GetType(System. String).ToStrin g
Return SqlTypes.SqlStr ing.Null
Case GetType(System. Boolean).ToStri ng
Return SqlTypes.SqlBoo lean.Null
Case Else
Return SqlTypes.SqlStr ing.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlStr ing.Null
End Try
End Function

Thanks for the help

Nicolas
Mar 28 '06 #1
1 1725
Function ReturnValue(ByV al thisObject As Object) As Object
Try
If IsNothing(thisO bject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the
type
Select Case thisObject.GetT ype.ToString
Case GetType(System. String).ToStrin g
Return SqlTypes.SqlStr ing.Null
Case GetType(System. Boolean).ToStri ng
Return SqlTypes.SqlBoo lean.Null
Case Else
Return SqlTypes.SqlStr ing.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlStr ing.Null
End Try
End Function

Nick,

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

Function ReturnValue(ByV al 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
2713
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> ErrorCodeOffset (Long Int) ErrorObjBaseName (Text(50)) ErrorDescription (Text(255)) 1 DontDoThat Hey! Don't do that!
19
4175
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 retrieve the values... (ie: application.currentproject.properties(propName)) b.) creating global variables in the form of an array and using a function to populate and retrieve them.
4
2731
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 error messages are thrown. The application, web based, late binds to a series of assemblies, none of which are in the GAC. I have configured the application to impersonate the IIS user and have set the user to have access to all relevant...
6
1590
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. ------------------------------------------------------------ Public Class MainForm Public Sub Show Form Try
1
6338
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 soap header called by using a http module. The problem Im having is I cannot seem to get the event to raise to fire off my authenticate method in the global.asax. The module is plumbed in to my web.config file Code Below:-
19
4923
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
7
7821
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}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
9
3278
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 these are similar: Create a new class (MyMembershipProvider and MyProfileProvider). Add the "Inherits..." value to the provider (MembershipProvider and ProfileProvider). Modify the web.config file to assign this class and it's connection...
1
4388
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 grid doesn't show colloections i.e. if I have a List<Objectthen the Collection is shown but when I click on the "..." button next to it nothing comes up. If I say CustomPropertyGrid p = new CustomPropertyGrid(); p.SelectedObject = new...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.