I have a label on a form that displays a float (_DataFloat) with a variable (_Digits) that sets the number of digits to show to the right of the decimal point. Assuming that _Digits can be any value from 0 through 6, is there a better way of formatting the text other than using a switch statement as below?
switch (_Digits) {
case 0:
label1.Text = _DataFloat.ToString("0");
break;
case 1:
label1.Text = _DataFloat.ToString("0.0");
break;
case 2:
label1.Text = _DataFloat.ToString("0.00");
break;
case 3:
label1.Text = _DataFloat.ToString("0.000");
break;
case 4:
label1.Text = _DataFloat.ToString("0.0000");
break;
case 5:
label1.Text = _DataFloat.ToString("0.00000");
break;
case 6:
label1.Text = _DataFloat.ToString("0.000000");
break;
default:
label1.Text = _DataFloat.ToString("0.00");
break;
}
How about:
var format = String.Format("0.{0}", new string('0', _Digits));
label1.Text = _DataFloat.ToString(format);
Related
I'm making a memory game in C#. It has 10 pairs of cards, total 20. It's supposed to work like this: When pressing the Start button, the game shuffles randomly the cards and reveals all cards. After 3 seconds it flips them. Then, the player has to find all pairs.
I'm having a problem with shuffling. I wrote this code. It's being executed when I press the Start button:
foreach (String icon in icons)
{
int x1 = r.Next(1, 21);
int x2 = r.Next(1, 21);
if (!num.Contains(x1))
{
num.Add(x1);
}
else
{
do
{
x1 = r.Next(1, 21);
} while (!num.Contains(x1));
num.Add(x1);
}
if (!num.Contains(x2))
{
num.Add(x2);
}
else
{
do
{
x2 = r.Next(1, 21);
} while (!num.Contains(x2));
num.Add(x2);
}
switch (x1)
{
case 1:
pictureBox1.Image = Image.FromFile(icon);
break;
case 2:
pictureBox2.Image = Image.FromFile(icon);
break;
case 3:
pictureBox3.Image = Image.FromFile(icon);
break;
case 4:
pictureBox4.Image = Image.FromFile(icon);
break;
case 5:
pictureBox5.Image = Image.FromFile(icon);
break;
case 6:
pictureBox6.Image = Image.FromFile(icon);
break;
case 7:
pictureBox7.Image = Image.FromFile(icon);
break;
case 8:
pictureBox8.Image = Image.FromFile(icon);
break;
case 9:
pictureBox9.Image = Image.FromFile(icon);
break;
case 10:
pictureBox10.Image = Image.FromFile(icon);
break;
case 11:
pictureBox11.Image = Image.FromFile(icon);
break;
case 12:
pictureBox12.Image = Image.FromFile(icon);
break;
case 13:
pictureBox13.Image = Image.FromFile(icon);
break;
case 14:
pictureBox14.Image = Image.FromFile(icon);
break;
case 15:
pictureBox15.Image = Image.FromFile(icon);
break;
case 16:
pictureBox16.Image = Image.FromFile(icon);
break;
case 17:
pictureBox17.Image = Image.FromFile(icon);
break;
case 18:
pictureBox18.Image = Image.FromFile(icon);
break;
case 19:
pictureBox19.Image = Image.FromFile(icon);
break;
case 20:
pictureBox20.Image = Image.FromFile(icon);
break;
}
switch (x2)
{
case 1:
pictureBox1.Image = Image.FromFile(icon);
break;
case 2:
pictureBox2.Image = Image.FromFile(icon);
break;
case 3:
pictureBox3.Image = Image.FromFile(icon);
break;
case 4:
pictureBox4.Image = Image.FromFile(icon);
break;
case 5:
pictureBox5.Image = Image.FromFile(icon);
break;
case 6:
pictureBox6.Image = Image.FromFile(icon);
break;
case 7:
pictureBox7.Image = Image.FromFile(icon);
break;
case 8:
pictureBox8.Image = Image.FromFile(icon);
break;
case 9:
pictureBox9.Image = Image.FromFile(icon);
break;
case 10:
pictureBox10.Image = Image.FromFile(icon);
break;
case 11:
pictureBox11.Image = Image.FromFile(icon);
break;
case 12:
pictureBox12.Image = Image.FromFile(icon);
break;
case 13:
pictureBox13.Image = Image.FromFile(icon);
break;
case 14:
pictureBox14.Image = Image.FromFile(icon);
break;
case 15:
pictureBox15.Image = Image.FromFile(icon);
break;
case 16:
pictureBox16.Image = Image.FromFile(icon);
break;
case 17:
pictureBox17.Image = Image.FromFile(icon);
break;
case 18:
pictureBox18.Image = Image.FromFile(icon);
break;
case 19:
pictureBox19.Image = Image.FromFile(icon);
break;
case 20:
pictureBox20.Image = Image.FromFile(icon);
break;
}
There is also an auxiliary list "num" and a list "icons", which contains the names of the icons' files.
List<int> num = new List<int>();
List<String> icons = new List<String>() { "agelada.png", "elefantas.png", "gata.png", "gatopardos.png", "kamilopardali.png", "liontari.png", "lykos.png", "skylos.png", "tigris.png", "zebra.png" };
This code is supposed to work like this:
~It generates two random numbers, from 1 to 20 (the game has 20 cards), and stores them into x1 and x2 respectively.
~For each icon, member of the "icons" list: If x1 isn't found in the list num, it gets added in it. If x1 is found, a new number is being generated, until generating one that isn't in "num". Then it gets stored in "num". Same for x2. This process repeats for all the member of the list "icons".
~Then, depending of the randomly generated numbers, the icon gets inserted into the respective pictureBoxes, for example, if the numbers are 6 and 17, the picture is entered into pictureBox6 and pictureBox17.
The goal of this process is to make sure that all 10 pictures are displayed exactly twice, to make pairs.
However, I have a problem. When I click on Start, not all cards are flipped (The question mark is the "back side" of the cards). It looks like this:
Picture
It's supposed to show animal pictures in all cards.
Any ideas?
In addition to the recommendations around managing the PictureBox controls in arrays, I would recommend you change the line (not shown) where you create the Random object to something like this:
Random r = new Random(10);
Setting the seed like this while you're debugging will let you predict the output, and as you step through code from one run to the next run, it's easier to follow what's happening.
That said, if you stepped through this code:
do
{
x1 = r.Next(1, 21);
} while (!num.Contains(x1));
num.Add(x1);
If you stopped the code on adding the value to your array, you would have seen the value already exists in the array, which is the opposite of the intended action. That means your loop is exiting at the wrong time.
In this case, it's because your check is the opposite logic of what it should be, you want to keep running through this loop while the value is in the array. In other words, changing both loops to look like this:
do
{
x1 = r.Next(1, 21);
} while (num.Contains(x1));
num.Add(x1);
You will end up filling up your array with 20 unique values.
I am currently working on migration of a vb.net desktop application into a web application, in the desktop application the previous developer had declared all the variables once on the
form_load
stdate = VB6.Format(Now, "mmddyyyyhh")
current_month = CInt(Mid(stdate, 1, 2))
current_day = CInt(Mid(stdate, 3, 2))
current_year = CInt(Mid(stdate, 5, 4))
current_hour = CInt(Mid(stdate, 9, 2))
base_year = current_year
this_year = current_year
base_month = current_month
this_month = current_month
txtBaseyear.Text = CStr(base_year)
txtBaseMonth.Text = CStr(base_month)
swyearerror = 0
They were then able to use these variables anywhere in the code and it would retain the values.
my application
protected void Page_Load(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
string format = "MMdyyyyhh";
string stdate = now.ToString(format);
Session["stdate"] = stdate;
int current_month = Convert.ToInt32(now.Month);
Session["currentmonth"] = current_month;
int current_day = Convert.ToInt32(now.Day);
Session["currentday"] = current_day;
int current_year = Convert.ToInt32(now.Year);
Session["currentyear"] = current_year;
int current_hour = Convert.ToInt32(now.Hour);
Session["currenthour"] = current_hour;
int base_year = (int)(Session["currentyear"]);
int this_year = (int)(Session["currentyear"]);
int base_month = (int)(Session["currentmonth"]);
int this_month = (int)(Session["currentmonth"]);
TxtBase.Text = Convert.ToString(base_year);
TxtBase1.Text = Convert.ToString(base_month);
}
Now each time there is a post-back when the text is changed the values are lost and set to zero so I tried storing it in a session but that still doesn't work.
Let me give you a visual of my situation.
1) on the first load everything loads fine.
2) then the users enters an item and hits enter
protected void TxtItem_TextChanged(object sender, EventArgs e)
{
Calc_Rotation();
Calc_Best_Before();
}
now...
public void Calc_Rotation()
{
switch (current_month) becomes 0 suppose to be 4
{
case 1:
rotation_month = "A";
break;
case 2:
rotation_month = "B";
break;
case 3:
rotation_month = "G";
break;
case 4:
rotation_month = "J";
break;
case 5:
rotation_month = "K";
break;
case 6:
rotation_month = "L";
break;
case 7:
rotation_month = "N";
break;
case 8:
rotation_month = "P";
break;
case 9:
rotation_month = "S";
break;
case 10:
rotation_month = "W";
break;
case 11:
rotation_month = "Y";
break;
case 12:
rotation_month = "Z";
break;
}
switch (current_hour) becomes 0 suppose to be the current hour
{
case 0:
case 1:
rotation_batch = 2;
break;
case 2:
case 3:
rotation_batch = 4;
break;
case 4:
case 5:
rotation_batch = 6;
break;
case 6:
case 7:
rotation_batch = 8;
break;
case 8:
case 9:
rotation_batch = 10;
break;
case 10:
case 11:
rotation_batch = 12;
break;
case 12:
case 13:
rotation_batch = 14;
break;
case 14:
case 15:
rotation_batch = 16;
break;
case 16:
case 17:
rotation_batch = 18;
break;
case 18:
case 19:
rotation_batch = 20;
break;
case 20:
case 21:
rotation_batch = 22;
break;
case 22:
case 23:
rotation_batch = 24;
break;
}
}
same goes for the Calc_Best_Before
after I tried the postback solution I am still getting 0 values.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;
DateTime now = DateTime.Now;
string format = "MMdyyyyhh";
string stdate = now.ToString(format);
Session["stdate"] = stdate;
int current_month = Convert.ToInt32(now.Month);
Session["currentmonth"] = current_month;
int current_day = Convert.ToInt32(now.Day);
Session["currentday"] = current_day;
int current_year = Convert.ToInt32(now.Year);
Session["currentyear"] = current_year;
int current_hour = Convert.ToInt32(now.Hour);
Session["currenthour"] = current_hour;
int base_year = (int)(Session["currentyear"]);
int this_year = (int)(Session["currentyear"]);
int base_month = (int)(Session["currentmonth"]);
int this_month = (int)(Session["currentmonth"]);
TxtBase.Text = Convert.ToString(base_year);
TxtBase1.Text = Convert.ToString(base_month);
}
Put your code inside the below code. If the web page loads for the first time IsPostBack property is 'false' and code inside the if condition will be executed.
if the page loads after a post back IsPostBack turns to 'true' which cause program execution to escape the if condition.
if (!IsPostBack)
{
}
In case you are using Session to store the values, you need to ensure that you are checking the IsPostBack Property. Otherwise, everytime the page postback occurs, you are initializing the values again and thus you loose the state.
Page.IsPostBack property basically signifies whether the Page is accessing the server for the first time or not.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTime now = DateTime.Now;
string format = "MMdyyyyhh";
string stdate = now.ToString(format);
Session["stdate"] = stdate;
int current_month = Convert.ToInt32(now.Month);
Session["currentmonth"] = current_month;
int current_day = Convert.ToInt32(now.Day);
Session["currentday"] = current_day;
int current_year = Convert.ToInt32(now.Year);
Session["currentyear"] = current_year;
int current_hour = Convert.ToInt32(now.Hour);
Session["currenthour"] = current_hour;
int base_year = (int)(Session["currentyear"]);
int this_year = (int)(Session["currentyear"]);
int base_month = (int)(Session["currentmonth"]);
int this_month = (int)(Session["currentmonth"]);
TxtBase.Text = Convert.ToString(base_year);
TxtBase1.Text = Convert.ToString(base_month);
}
}
UPDATE 1:
#CodeMan: You need to use the Session to read the value for the current month in the function Calc_Rotation. You are trying to read the value from the variable current_month which is an int and would default to zero.
I would suggest you to use a Property to wrap up the Session Variable and then use the property in the code. Below, i have created a wrapper property CurrentMonth which encapsulates the Read and write operations on Session in the webpage, declared at class scope. Simmilary you can create wrapper properties for other variables as well. After creating the properties, you need to read the property value in the Calc_Rotation function.
private int CurrentMonth {
get {
var monthfromSession = HttpContext.Current.Session["ClassNameSpace.CurrentMonth"];
return monthfromSession!= null ? (int)monthfromSession : 0;
}
set {
HttpContext.Current.Session["ClassNameSpace.CurrentMonth"] = value;
}
}
public void Calc_Rotation()
{
switch (this.CurrentMonth) // it should have correct month value now.
{
case 1:
rotation_month = "A";
break;
case 2:
rotation_month = "B";
break;
case 3:
....
}
}
I am trying to use the selectedItem command to see what has been selected in the list box and then use the switch to set the activityLevel variable depending on what has been selected. I then need to be able to multiply that variable by the BMR variable that is set as a double. Then the result is displayed in a label.
string activityLevel = lstActivityLevel.SelectedItem.ToString();
switch (activityLevel)
{
case 1:
activityLevel = Convert.ToInt32(ACTIVTY_LEVEL2);
break;
case 2:
activityLevel = Convert.ToInt32(ACTIVTY_LEVEL3);
break;
case 3:
activityLevel = Convert.ToInt32(ACTIVTY_LEVEL4);
break;
case 4:
activityLevel = Convert.ToInt32(ACTIVTY_LEVEL5);
break;
}
//Display BMR in label
lblBMRResult.Text = (BMR*activityLevel).ToString();
You can use SelectedIndex, then each item of lstActivityLevel set to number from 0 to 4:
double activityLevel = 0;
switch (lstActivityLevel.SelectedIndex)
{
case 0:
activityLevel = ACTIVTY_LEVEL1;
break;
case 1:
activityLevel = ACTIVTY_LEVEL2;
break;
case 2:
activityLevel = ACTIVTY_LEVEL3;
break;
case 3:
activityLevel = ACTIVTY_LEVEL4;
break;
case 4:
activityLevel = ACTIVTY_LEVEL5;
break;
}
lblBMRResult.Text = (BMR * activityLevel).ToString();
You convert SelectedItem value to string. And value 1 (int) is not the same as "1" (string)... So, you have to change your switch statement to:
switch (activityLevel)
{
case "1":
blah, blah...
break;
}
and so on..
Or do not call ToString() on SelectedItem.
Or you can use SelectedIndex instead of SelectedItem..
I am trying to create an application in C# that converts numbers in a text box to roman numerals in a label control and need to use a case statement. However one of my variable Roman gets the error message: Use of unassigned local variable 'Roman'.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Roman_Numeral_Converter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalc_Click(object sender, EventArgs e)
{
int Number=int.Parse(txtNum.Text); // To hold Number
string Roman; // To hold Roman Numeral
if (Number>=1 && Number <=10)
{
switch (Roman)
{
case "Number==1":
lblRoman.Text = "I";
break;
case "Number==2":
lblRoman.Text = "II";
break;
case "Number==3":
lblRoman.Text = "III";
break;
case "Number==4":
lblRoman.Text = "IV";
break;
case "Number==5":
lblRoman.Text = "V";
break;
case "Number==6":
lblRoman.Text = "VI";
break;
case "Number==7":
lblRoman.Text = "VII";
break;
case "Number==8":
lblRoman.Text = "VIII";
break;
case "Number==9":
lblRoman.Text = "IX";
break;
case "Number==10":
lblRoman.Text = "X";
break;
}
}
else
{
MessageBox.Show("Error: Invalid Input");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
txtNum.Text = "";
lblRoman.Text = "";
}
}
}
Your structure is a little off.
private void btnCalc_Click(object sender, EventArgs e)
{
var Number = int.Parse(txtNum.Text); // To hold Number
switch (Number)
{
case 1:
lblRoman.Text = "I";
break;
case 2:
lblRoman.Text = "II";
break;
case 3:
lblRoman.Text = "III";
break;
case 4:
lblRoman.Text = "IV";
break;
case 5:
lblRoman.Text = "V";
break;
case 6:
lblRoman.Text = "VI";
break;
case 7:
lblRoman.Text = "VII";
break;
case 8:
lblRoman.Text = "VIII";
break;
case 9:
lblRoman.Text = "IX";
break;
case 10:
lblRoman.Text = "X";
break;
default:
MessageBox.Show("Error: Invalid Input");
break;
}
}
You're using the lblRoman to hold your result, thus your Roman variable is unnecessary. Additionally, since you're interrogating every possible valid number in your switch, you can just use the default to replace your if/else structure.
I'm assuming you're doing this as an academic exercise. That being said, I would be remiss not to point to you Mosè Bottacini's solution to this problem.
This is because Roman variable is really unassigned. You should assign it before you enter the statement
try this,
when your number value like 1 so roman number is I.
private void btnCalc_Click(object sender, EventArgs e)
{
int Number = int.Parse(txtNum.Text); // To hold Number
string Roman; // To hold Roman Numeral
if (Number >= 1 && Number <= 10)
{
switch (Number)
{
case 1:
lblRoman.Text = "I";
break;
case 2:
lblRoman.Text = "II";
break;
case 3:
lblRoman.Text = "III";
break;
case 4:
lblRoman.Text = "IV";
break;
case 5:
lblRoman.Text = "V";
break;
case 6:
lblRoman.Text = "VI";
break;
case 7:
lblRoman.Text = "VII";
break;
case 8:
lblRoman.Text = "VIII";
break;
case 9:
lblRoman.Text = "IX";
break;
case 10:
lblRoman.Text = "X";
break;
}
}
else
{
MessageBox.Show("Error: Invalid Input");
}
}
Instead of switch, You can do other way using Linq which is even better.
int Number=int.Parse(txtNum.Text);
var romanList = new List<string> {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
if (Number >= 1 && Number <= 10)
lblRoman.Text = romanList.Select((r, i) => new { Roman = r, Index = i+1}).FirstOrDefault(x=> x.Index == Number).Roman;
you can replace your switch statement this way. and of course you need to assign a variable before using it.
public string GetNum(string val)
{
string res = ""; // Assign it an empty string.
var numToRom = new Dictionary<string, string>
{
{"1","I"},
{"2","II"}
//so on
};
numToRom.TryGetValue(val, out res);
return res;
}
I have the following stored procedure that I have to get data from:
EXECUTE [dbo].[StationHealthStatusSummary2]
#LineId varchar(100), // 5,9,10
#MeasurementDt datetime, //2012/06/06
#Ntotal Int output,
#N0 int output,
#N1 int output,
#N2 int output,
#N3 int output,
#N4 int output,
#N5 int output,
#N6 int output,
#N7 int output,
#N8 int output,
#N9 int output,
#N10 int output,
#N11 int output,
#N12 int output,
#N13 int output,
#N14 int output,
#N15 int output,
#N16 int output
GO
Now I can send parameters to LineID and Measurement date as follows:
SqlConnection sql = new SqlConnection(#"Data Source=(local)\SQLEXPRESS;Initial Catalog=iComs;Persist Security Info=True;User ID=sa;Password=Password);
SqlCommand getData = new SqlCommand("StationHealthStatusSummary2", sql);
SqlDataAdapter da = new SqlDataAdapter(getData);
getData.CommandType = CommandType.StoredProcedure;
getData.Parameters.Add(new SqlParameter("#LineId", Lines));
getData.Parameters.Add(new SqlParameter("#MeasurementDt", date1));
SqlParameter ParamaterNtotal = new SqlParameter();
ParamaterNtotal.ParameterName = "#Ntotal";
ParamaterNtotal.SqlDbType = SqlDbType.Int;
ParamaterNtotal.Direction = ParameterDirection.Output;
getData.Parameters.Add(ParamaterNtotal);
sql.Open();
getData.ExecuteNonQuery();
Now I can get the value of NTotal and assign it to a Teechart (PieSlice),
but how do I get the value for #N0..#N16?
I've got some code that might give you some idea of what I'm trying to accomplish.
int NTotal = int.Parse(getData.Parameters["#Ntotal"].Value.ToString());
if (GetVariantVariableI(getData.Parameters[0].Value) = 0)
{
for (c = 1; c <= 18; c++)
{
Nvl = GetVariantVariableI(getData.Parameters[2+c].Value);
switch(c)
{
case 1:
NTotal = Nvl;
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
cstatus = c-2;
NPieValues[cstatus] = Nvl;
break;
}
string SliceName;
int NUsed;
NUsed = 0;
for(i=0;i<=16;i++)
{
NUsed = NUsed + NPieValues[i];
}
if (NUsed < NTotal)
{
Chart1.Series[0].Add(NTotal - NUsed);
slice1.Title = "Not Connected";
slice1.Add();
slice1.Color = System.Drawing.Color.Silver;
}
if (NUsed > NTotal)
{
NPieValues[7] = NPieValues[7]-(NUsed-NTotal);
}
for (i=0;i<=16;i++)
{
if (NPieValues[i]>0)
{
switch(i)
{
case 0: SliceName ="Green";
break;
case 1: SliceName ="Yellow";
break;
case 2: SliceName ="Orange";
break;
case 3: SliceName ="Red";
break;
case 4: SliceName ="Broken Rail";
break;
case 5: SliceName ="Buckling Rail";
break;
case 6: SliceName ="Maintenance required";
break;
case 7: SliceName ="Station(s) Off";
break;
case 8: SliceName ="Rail Differential kN";
break;
case 9: SliceName ="Left Rail Sensor Faulty";
break;
case 10: SliceName ="Right Rail Sensor Faulty";
break;
case 11: SliceName ="Temperature Rail Sensor Faulty";
break;
case 12: SliceName ="Calibration Required";
break;
case 13: SliceName ="Station Vandalised";
break;
case 14: SliceName ="Station uninstalled";
break;
case 15: SliceName ="Gauges removed for Maintenance";
break;
case 16: SliceName ="No GSM Coverage";
break;
default:
SliceName ="?";
}
switch(i)
{
case 0: clr = "System.Drawing.Color.Green";
break;
case 1:clr = "System.Drawing.Color.Yellow";
break;
case 2:clr = "System.Drawing.Color.Orrange";
break;
case 3:clr = "System.Drawing.Color.Red";
break;
case 4:
case 5:
case 8:clr = "System.Drawing.Color.Purple";
break;
case 6:clr = "System.Drawing.Color.Black";
break;
case 7:clr = "System.Drawing.Color.Gray";
break;;
case 9:clr = "System.Drawing.ColorTranslator.FromHtml('#E0671F')";
break;
case 10:clr = "System.Drawing.ColorTranslator.FromHtml('#BA4EC2')";
break;
case 11:clr = "System.Drawing.ColorTranslator.FromHtml('#FF8000')";
break;
case 12:clr = "System.Drawing.ColorTranslator.FromHtml('#BF4093')";
break;
case 13:clr = "System.Drawing.Color.SkyBlue";
break;
case 14:clr = "System.Drawing.Color.Aqua";
break;
case 15:clr = "System.Drawing.ColorTranslator.FromHtml('#BFBFFF')";
break;
case 16:clr = "System.Drawing.Color.MedGray";
break;
default : clr = "System.Drawing.Color.White";
break;
}
slice1.Add(NPieValues[i],SliceName,clr);
}
}
}
}
}
Now after it got all those values it has to populate the piechart.
Please, any help will be highly appreciated and please tell me if I'm being too vague.
Thanks
You have added #Ntotal as an Output parameter, why didn't you add all the others?
SqlParameter n = new SqlParameter();
n.ParameterName = "#N0";
n.SqlDbType = SqlDbType.Int;
n.Direction = ParameterDirection.Output;
getData.Parameters.Add(n);
Then you can retrieve the output values the same way you do with #Ntotal. Also, you can retrieve the values by name instead of looping through them, if you prefer.
Thanks. I Figured it out...
after i send the parameters as follows:
SqlParameter Paramater0 = new SqlParameter();
Paramater0.ParameterName = "#N0";
Paramater0.SqlDbType = SqlDbType.Int;
Paramater0.Direction = ParameterDirection.Output;
getData.Parameters.Add(Paramater0);
I then get the value and declare it to a var as follows:
int N0 = int.Parse(getData.Parameters["#N0"].Value.ToString());
and finally declare that int to a slice on the chart as follows:
slice1.Add(N0, "Green", System.Drawing.Color.Green);
Thanks for your help #mgnoonan :)