Hy guys ! I created a database (.mdf) . Where I have a table. I have three columns where on each row of two columns i have a float and on the third column I want to display the average of the two numbers on the row. Please help!
Ps. Excuse my bad english:rolleyes:
How to calculate the average of two numbers in a table
Started by cismarel, Mar 28 2010 08:08 AM
14 replies to this topic
#1
Posted 28 March 2010 - 08:08 AM
|
|
|
#2
Posted 29 March 2010 - 08:58 AM
By table, you mean dataGridView?
(Salut!)
(Salut!)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#3
Posted 29 March 2010 - 09:04 AM
[SIZE=2]int[/SIZE] averge = 10;
dataGridView1.Rows[0].Cells[3].Value = averge.ToString();
Instead of [0] use a for loop to loop through all the rows.
Mult Noroc!
dataGridView1.Rows[0].Cells[3].Value = averge.ToString();
Instead of [0] use a for loop to loop through all the rows.
Mult Noroc!
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#4
Posted 29 March 2010 - 09:10 AM
Thanks! Esti din Romania?
#5
Posted 29 March 2010 - 09:25 AM
Fii atent *** am.
prtsc..jpg 464.39K
511 downloads Am schimbat modul de introducere de la tabel la details(pt ca aveam prea multe coloane). Nu am multa experienta in c#. Eu vreau ca camplu Medie A1 sa fie read-only ( asta stiu sa fac) si sa afiseze (medie S1A1 + medie S2A1)/2. Multumesc pentru ajutor!
prtsc..jpg 464.39K
511 downloads Am schimbat modul de introducere de la tabel la details(pt ca aveam prea multe coloane). Nu am multa experienta in c#. Eu vreau ca camplu Medie A1 sa fie read-only ( asta stiu sa fac) si sa afiseze (medie S1A1 + medie S2A1)/2. Multumesc pentru ajutor!
#6
Posted 29 March 2010 - 09:25 AM
*** = c_u_m
#7
Posted 29 March 2010 - 09:46 AM
cismarel said:
Fii atent *** am.[ATTACH=CONFIG]2875[/ATTACH] Am schimbat modul de introducere de la tabel la details(pt ca aveam prea multe coloane). Nu am multa experienta in c#. Eu vreau ca camplu Medie A1 sa fie read-only ( asta stiu sa fac) si sa afiseze (medie S1A1 + medie S2A1)/2. Multumesc pentru ajutor!
Nu ai multa experienta in C#? Bazele de date sunt o chestie destul de grea sa stii. Se pare ca stie Google ce stie. Pai,
medieA1.Text = (double.Parse(medieS1a1.Text) + double.Parse(medieS2A1))/2.ToString();
double.Parse("string") converteste din string in double.
P.S. -> Evita sa publici idea de aplicatie pe forumuri daca participi la concursuri. In cazul asta ai dat si screenshot... ce sa mai zic...
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#8
Posted 29 March 2010 - 09:47 AM
cismarel said:
Thanks! Esti din Romania?
Nu, am invatat romana din pasiune :)). (ironic)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#9
Posted 29 March 2010 - 09:47 AM
cismarel said:
*** = c_u_m
LOL!
(For english speakers: c_um = how in romanian)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#10
Posted 29 March 2010 - 10:02 AM
If you are actually averaging the numbers in your db (.mdf file) and not your gridview there is an SQL function for average (AVG() i believe but my sql is a bit rusty so you probably want to check that out.) This will average your numbers before you querry them all into a c# object. This can be very adventageous when you are dealing with large amounts of data as you wont be spending large amounts of time querying numbers that you are going to average anyways; instead the averaging will be done on the db server and will only send u the pertinent info. I realize that if you need the full table for other calculations (or simply for display purposes) anyway, or are dealing with only a few pieces of data, than this is not usefull to you. I did think it was worth mentioning for others who are looking for the same sort of thing.
#11
Posted 29 March 2010 - 11:30 AM
Thanks a lot guys !
For Davide: Merci pt sfat ;am 16 ani si fac aplicatia asta pt un concurs care e peste 2 luni, tocmai din cauza ca nuprea stiu baze de date m-am apucat de acum ( defapt inafara de partea wysiwyg ai lui c# 2008 nuprea stiu mult cod). Nu mai cunosc decat singur baiat (care e cu un an mai mare decat mine) care sa lucreze in c# ;deobicei la varsta mea copiii merg pe html sau php(dar mai rar) si cel mai frecvent pe powerpoint (in care imi e si sila sa fac proiect) deci nici nu ma pot gandi ca cineva imi poate fura ideea cu toate ca nu e una foarte stralucita pot spune ca mai degraba e muncitoreasca. Programul care mi-am propus sa-l fac vrea sa stocheze cam toate informatiile despre o scoala si sper sa-l reusesc sal fac pana la deadline. Merci mult pentru ajutor! :thumbup:
P.S. Am o sa am o gramada de intrebari.
For Davide: Merci pt sfat ;am 16 ani si fac aplicatia asta pt un concurs care e peste 2 luni, tocmai din cauza ca nuprea stiu baze de date m-am apucat de acum ( defapt inafara de partea wysiwyg ai lui c# 2008 nuprea stiu mult cod). Nu mai cunosc decat singur baiat (care e cu un an mai mare decat mine) care sa lucreze in c# ;deobicei la varsta mea copiii merg pe html sau php(dar mai rar) si cel mai frecvent pe powerpoint (in care imi e si sila sa fac proiect) deci nici nu ma pot gandi ca cineva imi poate fura ideea cu toate ca nu e una foarte stralucita pot spune ca mai degraba e muncitoreasca. Programul care mi-am propus sa-l fac vrea sa stocheze cam toate informatiile despre o scoala si sper sa-l reusesc sal fac pana la deadline. Merci mult pentru ajutor! :thumbup:
P.S. Am o sa am o gramada de intrebari.
#12
Posted 29 March 2010 - 02:07 PM
I'm not gonna waste my time using google translator to help someone that doesn't really care to deliver his question clearly. USE ENGLISH!


Sign In
Create Account


Back to top









