|
no i posted my codesnippet as
For (int i=0;i
|
|
|
|
|
ur text box is truncate the code...pls check the code project page
regards
ybasha
|
|
|
|
|
ybasha wrote: 'where identifier='" + Id +"'";
Unless your unique ID is a string, you need to remove the quotes.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Since you didn't cut an paste the real code (as evidinced by the incomplete for statement) it is possible that the error message is correct: Var1 doesn't exist in the posted code. its var1... C# is after all case sensitive...
This would be better done as a parameterized query anyway. Parameters have fewer issues with text characters (don't mind unescaped single quotes for instance) and so are less likely to give strange errors than dynamically built SQL.
I notice that two or more of your replacements are replaceing unicode characters with double quotes, which likely totally corrupt the concatenated query sting (causing it to appear to terminate early). Using parameters would avoid that issue as well.
Christian's observation is also likely a problem, and is another that would be avoided by using parameters.
Building up SQL statements by concatenating stuff like this is bad practice for a number of reasons (increased garbage generation from all the string reallocations, vulnerability to SQL injection attack, etc).
[edit] On top of all that, all the string variables (var1, var2, etc) are declared inside the scope of the for loop, and so do not exist outside of it (where your sql sting is declared and concatenated)...move the declarations to before the for loop, and this might have a chance [edit]
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
-- modified at 0:00 Wednesday 26th October, 2005
|
|
|
|
|
It looks like Var1 is outside the scope of the loop.
|
|
|
|
|
did you spell the variables correctly (i.e Var1 != var1)?
|
|
|
|
|
Not really related to your question, but I hope you are aware that you can convert between code pages/encodings in a few lines (this looks like UTF-8 read as for example cp1252).
If it is indeed the case do something like this:
byte[] bytes = System.Text.Encoding.GetEncoding(1252).GetBytes(sourceString);
string result = System.Text.Encoding.UTF8.GetString(bytes);
|
|
|
|
|
I need help to write a program that includes two functions named calc_avg() and varience(). The calc_avg() function should calculate and return the average of the values stored in a static array called testvals. The array should be declared in main() and include that values 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, and 73. The varience is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. The values returned from calc_avg() and varience() should be displayed in main()???
|
|
|
|
|
No - we won't do your homework. You need to try to do it yourself. This problem is kind of trivial - have you been paying attention in class ?
If you get stuck, you can ask *specific* questions. Posting your homework question without trying to do it yourself is not what this forum is for.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This sounds like homework? If so, shouldn't you be able to do this by yourself if you paid attention in class?
You say that you need help to write the program. What kind of help?
---
b { font-weight: normal; }
|
|
|
|
|
This is the part i'm stuck on, i don't understand the coding for this last part, the rest i have done, it's the end that's stalling me, i do pay attention in class but people do get stuck sometimes
thanks,
....The varience is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. The values returned from calc_avg() and varience() should be displayed in main()???
|
|
|
|
|
Right, what part are you getting stuck at? Have you squared, added, and divided the values? Are you having trouble writing the values to stdout? What's the problem?
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
I readded u to my MSN again. Did you get the request?
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
Got it.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
here's my code so far:
[STAThread]
static void Main(string[] args)
{
double [] testvals = new double [14];
testvals [0] = 89;
testvals [1] = 95;
testvals [2] = 72;
testvals [3] = 83;
testvals [4] = 99;
testvals [5] = 54;
testvals [6] = 86;
testvals [7] = 75;
testvals [8] = 92;
testvals [9] = 73;
testvals [10] = 79;
testvals [11] = 75;
testvals [12] = 82;
testvals [13] = 73;
}
static double [] calc_avg (double []testvals)
{
double [] avgerage = new double [14];
for(int i = 0; i<14; i++)
{
average[i] = testvals[i]/14;
}
return average;
}
static double [] variance (double [] calc_avg, double []testvals)
{
double []variance = new double [14];
for (int i = 0; i<14; i++)
{
variance[i] = (average[i] - testvals[i])^2
Now, i'm stuck with writing the part where you have to : The variance is obtained by subtracting the average from EACH VALUE in testvals, SQUARING THE VALUES OBTAINED, ADDING them, DIVIDING by the number of elements in testvals. The values returned from calc_avg() and variance() should be DISPLAYED IN THE MAIN..........the bolded words are where i'm getting stuck, do i do this all in one line, or multiple, or what does the coding look like???
|
|
|
|
|
Zjaded wrote: for (int i = 0; i<14; i++)
{
variance[i] = (average[i] - testvals[i])^2
SQUARING THE VALUES OBTAINED, ADDING them, DIVIDING
So you've subtracted the values from the average for each value already. Now sum all the values in variance[i], divide it by 14 (i.e. take the average of them).
Zjaded wrote: DISPLAYED IN THE MAIN
I assume they mean write it to the console?
|
|
|
|
|
If you've already done some of it, why did you ask for help with all of it ?
Zjaded wrote: subtracting the average from each value in testvals
Do you know how to calculate an average ?
Zjaded wrote: squaring the values obtained
Math.Pow, or just x*x.
Zjaded wrote: adding them, and dividing by the number of elements in testvals
Which bits are you stuck on here ? Post your code, and explain where you can't work out how to proceed.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey
its the first time I'm trying to draw something myself, so its pretty basic...
well, I have 2 questions:
1. how can I draw just one dot on the screen? not a line, not a rectangle, just one simple dot (color a specific point).
I tried to draw a line from a point to the same on (drawline(pen, point1, point1)), but it didn't work...
2. is it possible to flip the (x,y) positions of the window?
so my x,y won't start at the upper-left side, but at the buttom, or at the middle of my window.
Thanks alot for your help!
|
|
|
|
|
SetPixel.
You can do a translateTransform, which means that you change where 0,0 is considered to be.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks!
|
|
|
|
|
about the SetPixel.
I cannot find SetPixel for a graphic object, only for Bitmap object.
I want to draw on the window itself, not on a bitmap.
I tried this code:
creating a bitmap on the window, and draw on it, but it doesn't work.
X=1;
Y=1;
Bitmap bp = new Bitmap(this.Width, this.Height);
bp.SetPixel(X, Y, System.Drawing.Color.Black);
thanks again!
|
|
|
|
|
Yes, SetPixel is a method on the Bitmap. I'm not sure why drawing a one pixel long line would fail to work though ( although I've never tried it ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
what I am trying to do is to draw a mathimatical function, something like:
y = x^2 + x + 1
just as example,
so I wrote a for loop from x= -50 to x= +50, and I want c# to put a black dot at each x,y , but instead of drawing that, it does nothing...
if you have any idea why it wouldn't work, I'll be more than greatful!
thanks again!
|
|
|
|
|
I don't understand why you can't just draw onto a bitmap and draw that to the screen. The other thing is, you can draw a line from each x value to the next one.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I know I can draw a line from one X to the other, but I want to do it in dots.
and about why I can't draw onto a bitmap and than draw that on the screen, I don't know why it doesn't work... yet
|
|
|
|
|