|
Hi,
I'm displaying data from a stored procedure in excel, columns which have null values in database are displayed
#VALUE! in Excel, what should i do so that i can display them as blank cells?
thanks
|
|
|
|
|
|
|
Hello,
I found a way to resolve this, it is just about adding a test on the value i want to display, i added a test if it is null, i affect an empty string to it, below my code:
<pre> for (int j = 0; j <= rows - 1; j++)
{
var rowItem = dt.Rows[j].ItemArray;
for (int k = 0; k <= rowItem.Length - 1; k++)
{
if (String.IsNullOrEmpty(rowItem[k].ToString()))
allRecords[j + 1, k] = string.Empty;
else
allRecords[j + 1, k] = rowItem[k];
}
}
Thanks ,
|
|
|
|
|
So I very recently started learning my first coding language at college, which is C#, i have an assignment in for Tuesday and cant for the life of me figure out how to complete one of the tasks it asks of me. The task is as follows:
"Write example program code that demonstrates the use of a function that calculates and returns the mean average of 5 values that are passed to it."
If anyone could walk me through what to do or give me some example code as to how they would approach this task then that would be most appreciated.
(I'm using VisualStudio)
|
|
|
|
|
This weekend would be the best time to start learning in C# functions.
To jump start, create a new project in visual studio and choose C#->Windows->Console Application.
class Program
{
static void Main(string[] args)
{
decimal[] values = new decimal[] { 1, 2, 3, 4, 5 };
decimal result = MeanAvg(values);
}
static decimal MeanAvg(decimal[] values)
{
decimal result = 0;
return result;
}
}
|
|
|
|
|
You could also do it this way:
static void Main()
{
double answer = MeanAvg(1,2,3,4,5);
double answer2 = MeanAvg(1,2,3,4,5,6,7,8,9,10);
}
static double MeanAvg(params int [] values)
{
double total = values.Average();
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Or this, which has the added benefit of handling a mix of numeric data types, and will throw an exception if you try to pass something that can't be converted to a numeric type:
private static double MeanAvg(params object[] values)
{
return Convert.ToDouble(values.Select(Convert.ToDecimal).Average());
}
These will work:
double answer = MeanAvg(1M,3,3d);
answer = MeanAvg(1M,3M,"3");
But this will throw an exception:
double answer = MeanAvg(1M,3M,"abc");
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
This is a trivial piece of code, and you still have a week. It's a shame that you have been given the solution; the sentence in bold explains quite well what needs to be done.
As for your ASAP; we're volunteers, and even if you were paying me I would not accept it. This ain't the army, and as soon as possible is when it damn well pleases me
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Did you attend the "classes".
How can you have an assignment and not be able to figure it out for "the life of (you)"?
And I thought "mean" AND "average" together was redundant. (As in, the "average" of the average?)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Why were my answers voted down? They damn well provided a correct answer. This is complete bullsh|t.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
@john-simmons-outlaw-programmer @cyborgkagaw
edit ...
After thinking this over, I have decided that my down-voting posts from Simmons and Gayo was a mistake. I apologize to both of them, and I have up-voted their posts to counteract the down-vote,
While I find the posting of ... what I perceive as ... homework solutions for obviously gimme-codez OP's disturbing, it's obvious to me that my taking this on ... without being part of a sanctioned and widely supported effort by many MVP'a and Mentors ... will just create chaos and bad-feeling.
We're here because we love to code ... aren't we ?
sincerely, Bill
... end edit ...
I have up-voted posts from Vluggen and Schmitz, and down-voted posts from Simmons and Gayo for the following reasons:
If we provide code to people that helps them avoid/shirk their homework, we are degrading the educational process, and contributing to the OP's failure to learn and grow: we are fostering dependency and laziness.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 14-Apr-18 8:40am.
|
|
|
|
|
BillWoodruff wrote: If we provide code to people that helps them avoid/shirk their homework, we are degrading the educational process, and contributing to the OP's failure to learn and grow: we are fostering dependency and laziness.
Down-voting CORRECT answers is bullsh|t, Bill, regardless of whether or not YOU believe that the user should have gotten said answer.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: Down-voting CORRECT answers is bullsh|t, Bill I take the responsibility I believe is involved in being a Mentor on this site seriously.
You continue to be someone I respect technically, and whose many contributions to this site, I have learned from.
sincerely, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Yes. The "good samaritan" law should apply. Just don't move them.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yeah, I've been snarky in the past with people asking questions regarding their homework, but I've NEVER down-voted someone's answer simply because the guy asking the question is too lazy to figure it out on his own. NEVER.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Should we get your approval before answering questions from now on?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: Should we get your approval before answering questions from now on? No !
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Oh wait! If you'll give me your email address, I'll send you all my code for either your approval, or a list of ambiguous hints and criticisms about where I might have gone wrong before I check it in to TFS. Oh yeah, don't forget to include a lecture on the evils of asking a question on CodeProject. You know - so we don't foster dependency and laziness.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
At least he is honest about it and providing a comment to explain it. You'd be usually the first to sneak something into the solution to get the kid in trouble
A downvote just costs some points, and we have enough to spend.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It's not about the points. It's about down-voting an answer the is CORRECT, because that reflects on ME.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
So does the rest of the thread.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And I already had that rep, so no harm, no foul. You should have seen the stuff I didn't post...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
So here we are. I provided an answer (two, in all actuality), and my answers were down-voted because some pompous ass decided that you didn't deserve the answer I provided.
I didn't provide any guidance, because I don't know if you're TRULY serious about being a programmer, or just taking an elective course to fulfill diploma requirements.
If you're serious, you gotta learn to THINK like a programmer. That means taking a project, breaking it down into logical steps, writing psuedo-code, and then writing actual code.
I'm assuming your instructor taught you about functions, and how they work. Actually, they're called METHODS, and all methods technically return a value, whether it's void or some other type. Methods also (optionally) accept one or more parameters. So let's break down your requirement into easily consumable requirements:
0) write a program that demonstrate the use of a function (method)
1) the function calculates an average of five values
2) the function returns the calculated average
Notice that there is no specification regarding WHERE the function gets the five values. This means you can set up a globally accessible collection of values, or pass parameters to the function. It's your choice how to proceed here.
Once you've decided which way you're going to provide the consumable data (the five values), you can craft your method prototype accordingly.
The body of the method has two processes - calculate the average of the values provided, and return the resulting average.
It's really just that simple (if you were in class for the instructor's guidance regarding the assignment, and paying attention).
If you want definitions for any of the nomenclature I've used above, google is your friend. You certainly shouldn't expect any specific help here, because after all, this is a homework question, and Bill simply won't let that happen.
----------------
Now, that too way too much f*ckin time to type. I don't really care if you are serious about being a programmer, or that this is even homework. I'm not your instructor, and it took LESS of my VALUABLE time to simply "give you the codez" than to give you most of the lesson you should have gotten from your instructor.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 13-Apr-18 15:31pm.
|
|
|
|
|
|