|
-
Mar 4th, 2005, 06:46 AM
#1
Thread Starter
Member
Big Problem
I would be soooooo grateful if someone could give me an answer to this. I am taking data from Excel to VB.NET and validating it within the VB.NET program. Some of the data in the spreadsheet comes out as dbnull. I am currently converting the data to a string becuase of this but need to do some calculation on it so it needs to be in int format. Is there any way of converting a dbnull to some type of numerical integer?
Thank you so much
Julie
-
Mar 4th, 2005, 07:22 AM
#2
Member
Re: Big Problem
I'd assume you are assigning the values taken from Excel to variables or integers, so I'd use a If... Then.. statement or somthing with the IsDBNull method. for example:
VB Code:
If IsDBNull(Whatever) then
Whatever = "<This field is Null>"
End If
Thats best I can do without seeing some of your code or knowing exactly what you are doing. But if you need any more help feel free to email me at [email protected].
-
Mar 4th, 2005, 07:31 AM
#3
Re: Big Problem
Well, it rather depends on how you are calculating things.
VB Code:
if whatever is dbnull.value then myValue = 0
Might work or it might not depending on your formulae.
Alternatively, using Single instead of integer will let you use Single.Nan in stead of the zero above. It won't be a numerical value but it will be a single.
I don't live here any more.
-
Mar 4th, 2005, 07:42 AM
#4
Thread Starter
Member
Re: Big Problem
Thank you for your help.Because it is going straight into a database I would rather not program another if statement.
at the moment this works dr("value").ToString
BUT
it doenst work for values with a minus and saying to int will not work on dbnull!!such a dilemma,are there any other datatypes which could possibly handle this?
Last edited by jewly; Mar 4th, 2005 at 07:46 AM.
-
Mar 4th, 2005, 10:09 AM
#5
Re: Big Problem
 Originally Posted by jewly
Because it is going straight into a database I would rather not program another if statement.
I'm having trouble understanding your situation. Can you post the chunk of code that you are having problems with (ie the whole subroutine).
I see you have 2 further options:
1. Write a class or a structure that can handle the problem and still be used in formulas.
2. use an IF statement (why don't you like if statements?)
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|