Solved

Dataset Column Expression With Conditional Outputs

Posted on 2004-09-20
7
440 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
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
Comment Utility
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
Comment Utility
Could you post your expression maybe you made a small type error.
0
 

Author Comment

by:nathanpz
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now