08-05-2017 07:06 PM
Hi All
Over the years i have built code for my Act database it is however rather raw, i have one lot of code that relies on about 30 fields being not NULL, if one is NULL it kicks the code out with an error message exception and its a pain to work out which one kicked the code
I want to write some checking code eg: IF NULL or IF NOT NULL which i know how to do
But if it triggers the NULL code whats the line to kick the process out and finish the code??? Or how to build in specific exceptions?
Thanks
08-07-2017 01:56 PM
That's much simpler than what I thought earlier. The code below is off the top of my head as I'm creating this post, so there could be issues.
Private Function HasNull(byval data as System.Data.Datarow) As Boolean Dim nullValue as Boolean = False For each o as Object in data.ItemArray If o = DBNull.Value Then nullValue=True Exit For End If Next Return nullValue End Function
So that would be the test. Then you'd just need to call that in your main method, such as:
'... previous code If HasNull(myDataRow) = False Then ' Do all of your processing here End If
This is a very basic/generic example, so if you need more complexity, you'll have to build it up. If you want a list of fields that are null, you'd want to return a list of strings or something like that instead of Boolean.
08-07-2017 05:39 AM
It sounds like you have a bit of restructuring to do. You're going to have to look over your existing code and processes. For each field, you'll have to ask questions like "Can I safely skip over this field or does something later on depend on this?" Based on the answers, you'll have to develop a means of handling the zero to many NULL fields. Without knowing anything about your code, my thought process went to how I would do this. For me, it would be nice to pass my row or data structure to a routine that spits out a list of fields that are null. In my main processing routine, I'd try to loop through that list or use it in a test (if field in Null-List, skip it), but it really depends on what you are trying to accomplish. Other than that, that's all I can really provide. Hopefully this will spark an idea or two.
08-07-2017 01:30 PM
08-07-2017 01:34 PM
08-07-2017 01:42 PM
08-07-2017 01:56 PM
That's much simpler than what I thought earlier. The code below is off the top of my head as I'm creating this post, so there could be issues.
Private Function HasNull(byval data as System.Data.Datarow) As Boolean Dim nullValue as Boolean = False For each o as Object in data.ItemArray If o = DBNull.Value Then nullValue=True Exit For End If Next Return nullValue End Function
So that would be the test. Then you'd just need to call that in your main method, such as:
'... previous code If HasNull(myDataRow) = False Then ' Do all of your processing here End If
This is a very basic/generic example, so if you need more complexity, you'll have to build it up. If you want a list of fields that are null, you'd want to return a list of strings or something like that instead of Boolean.