dhj Posted August 16, 2004 Posted August 16, 2004 i have a typed dataset, one field is allow null,(say FirstName is allow null) when i'm retreiving data to the UI i need to check FirstName for null values so i'm doing this as follow say my types dataset is ds and oRow is the pointed row with oRow txtFirstName.Text=IIF(.IsFirstNameNull,"",.FirstName) end With but my problem is this IIF doesn't work propery. if i did this using if else statements without using IIF it is working properly pls help me, pls explain me y this IIF is not function properly,this is in my windows application and i'm using vb.net thank you Quote
AlexCode Posted August 16, 2004 Posted August 16, 2004 I really don't know why by maybe if you try to work aroud the evaluation it will work... Something like: txtFirstName.Text=IIF(.FirstName = dbnull.value,"",.FirstName) Try it... If not... use the If-> Else... How bad could it be?? :cool: Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Arch4ngel Posted August 16, 2004 Posted August 16, 2004 If -> Else and IIF will probably give exactly the same assembly anyway. So if it don't work with IIF then ... If Else Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Joe Mamma Posted August 16, 2004 Posted August 16, 2004 with oRow txtFirstName.Text=IIF(.IsFirstNameNull,"",.FirstName) end With cant you just do - with oRow txtFirstName.Text=Convert.ToString(.FirstName) end With Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
AlexCode Posted August 16, 2004 Posted August 16, 2004 If -> Else and IIF will probably give exactly the same assembly anyway. So if it don't work with IIF then ... If Else Arch4ngel: That's the logic but as dhj said: if i did this using if else statements without using IIF it is working properly Starnge, not logical... but as stated... true... Anyways... Joe Mamma's idea seems fine to me as I see it... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
dhj Posted August 17, 2004 Author Posted August 17, 2004 hi all thank you very much for all of u for ur comments i have tried Alex's method txtFirstName.Text=IIF(.FirstName = dbnull.value,"",.FirstName) it is giving me a error as "Operator '=' is not defined for types 'String' and 'System.DBNull'. Use 'Is' operator to compare two reference types." and then i tried Joe Mamma's method txtFirstName.Text=Convert.ToString(.FirstName) but still the same problem occures ofcause as u guys said i can easily go for if.. else ... statement. but imagine if i have plenty of allow null fields, then i need to write if .. else statement for each and every one. that is y i have selected IIf to do me the job. but still i cannot figure out y this is not functioning propery. as u guys said IT IS STRANGE..... Quote
AlexCode Posted August 17, 2004 Posted August 17, 2004 Did you do what the "guy's" asking? Replace the '=' by 'IS'... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
dhj Posted August 17, 2004 Author Posted August 17, 2004 yes alex i have tried that too. but still the problem is there. :confused: Quote
JABE Posted August 18, 2004 Posted August 18, 2004 I once encountered a similar problem, something like: val = IIF(otherVal Is DBNull.Value, 0, Convert.ToDouble(otherVal)) then I remembered that IIF evaluates BOTH true and false parts of the IIF arguments, regardless if the 1st param is actually true or false, hence the error (btw, the same is not true for C#'s conditional operator ?: ) I guess you really have no choice but to use If...Else...End If blocks; if you're concerned about the resulting verbosity of your code, then you might want to encapsulate this logic in a function. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.