Solved

Dataset Column Expression With Conditional Outputs

Posted on 2004-09-20
7
443 Views
Last Modified: 2010-08-05
Hi,

How do you set a column expression to assign a large number of string values that are determined by an existing column value?

I have numbers ranging from 0 to 30 say in my existing [New Score] column. I wan't my column expression on my [Level] column to show the following:

New Score                 Level

1-3                              A
3-6                              B
6-9                              C
etc                              etc
24-27                           I
27-30                           J

I have used an IIF statement before to handle just two classifications "High" and "Low" levels, but cannot get VB.NET to extend to the multiple-argument. The line below works fine for two [Level] values only.

ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 15, 'Low', 'High')"

How do I get more than a true/false conditional expression?

Thanks,
Nathan.
0
Comment
Question by:nathanpz
  • 5
  • 2
7 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12109705
Well you could nest your iif, like

Dim s As Integer = 12
       ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 4, "A",IIF([New Score] < 7,"B", IIF([New Score] < 10,"C", etc... )"
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12109734
or you could use the switch function, something like

dim s as integer = 9
MsgBox(Microsoft.VisualBasic.Switch(s < 4, "A", s < 6, "B", s < 10, "C"))
0
 

Author Comment

by:nathanpz
ID: 12119083
Hi RonaldBiemans,

I don't think the IIF statement can be nested in VB.NET. It says I am using too many arguments if I have more than IIF(argument,val_true,val_false).

Also, the Switch function wont allow me to use the [New Score] column values. I can't easily code the switch function to alter each [Level] column entry because the [Level] column is readonly and part of a dataset so it needs to use the Dataset.DataColumn.Expression command. Do you know how this could be coded?

Any ideas how to alter on of the above functions to work with my dataset column?

Thanks,
Nathan.

0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12120526
I'll have a look, but I'm pretty sure the iif can be nested.
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 12120602
Hi nathanpz, I tested it and it works

ds.Tables(0).Columns("scores").Expression = "IIF([tata] < 4, 'A',IIF([tata] < 7,'B', IIF([tata] < 10,'C', IIF([tata] < 15,'D','E'))))"
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12120606
Could you post your expression maybe you made a small type error.
0
 

Author Comment

by:nathanpz
ID: 12128782
Thanks for persevering RonaldBiemans,

I wasn't being careful enough with the number of arguments in the nested IIF statement.

The points are yours.

Thanks again.
Nathan.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question