eyes73 reputationPosted Nov 24, 2004, 12:16 AM EST
0
Hi,
Hope, u are set the values in the datagrid through any one of the DataSource.
For example DataTable or DataSet or etc . . .
So through that DataSource itself u can calculate what u want . . .
Once u change the values in the datagrid during runtime,
it is updated in the data source also . . .
So u can use it . . .
Example:
Let us consider a DataTable as a data source . . .
First let we create a DataTable object with some values . . .
DataTable dataTable = new DataTable ( ) ;
dataTable.Columns.Add ( "Numbers" ) ;
DataRow dr = null ;
dr = dataTable.NewRow ( ) ;
dr[ "Numbers" ] = 3 ;
dataTable.Rows.Add ( dr ) ;
dr = dataTable.NewRow ( ) ;
dr[ "Numbers" ] = 5 ;
dataTable.Rows.Add ( dr ) ;
dr = dataTable.NewRow ( ) ;
dr[ "Numbers" ] = 8 ;
dataTable.Rows.Add ( dr ) ;
dataGrid1.DataSource = dataTable ; // To set the data source to datagrid . . .
Then we can find the average by,
decimal sum = 0 ;
for ( int i=0; i
aylin_sk87 reputationPosted Nov 24, 2004, 12:31 AM EST
0
For example in a datagrid, I have columns...And inside one column there are lots of numbers(values)..I want to find the average of these numbers..Give me an example..
Hi,
Yes. I think U'll get the values as rows and columns from the oracle database as a DataSet or a DataTable and then set set those to the DataGrid . . .
So U can use that DataSet or DataTable ( which U used as a DataSource for the DataGrid ) directly, not the datagrid . . .
I think Ur using Odbc, so the code MAY look like this . . .
string connectionString = "" ; // Please enter the connection string . . .
System.Data.Odbc.OdbcConnection connection = new System.Data.Odbc.OdbcConnection ( connectionString ) ;
System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand ( ) ;
command.Connection = connection ;
System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter ( command ) ;
adapter.SelectCommand.CommandText = "" ; // Please enter the SQL SELECT command string . . .
System.Data.DataSet dataSet = new DataSet ( ) ;
adapter.Fill ( dataSet ) ;
Now u can use this dataSet or dataSet.Tables[0] as a data source for the data grid . . .
Cheers,
Kanna . . .
aylin_sk87 reputationPosted Nov 24, 2004, 2:59 AM EST
0
Kanna hi,
After I wrote this code, will I write datasource code like this??
string connectionString = "" ; // Please enter the connection string . . .
System.Data.Odbc.OdbcConnection connection = new System.Data.Odbc.OdbcConnection ( connectionString ) ;
System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand ( ) ;
command.Connection = connection ;
System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter ( command ) ;
adapter.SelectCommand.CommandText = "" ; // Please enter the SQL SELECT command string . . .
System.Data.DataSet dataSet = new DataSet ( ) ;
adapter.Fill ( dataSet ) ;
dataGrid1.DataSource = dataTable ; // To set the data source to datagrid . . .
Then we can find the average by,
decimal sum = 0 ;
for ( int i=0; i
Hi,
U've to write this where u need the average ? ? ?
Also add appropriate database connection string and select query . . .
Please check this code. I didn't run this . . . Hope it is correct ? ? ?
Cheers,
Kanna . . .
Ryan AlfordRank #1,411 · 1.2K reputationPosted Dec 24, 2008, 7:30 AM EST
0
c'mon Bechir, this topic is over 4 years old.
0
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 24, 2008, 12:25 PM EST
0
Inspite of it's old you can get the column average in a single line of code using the 10th formulat look again on the article. The essencial is the efficiency and not the old my freind ;-}
eyes73 reputationPosted Nov 23, 2004, 4:07 AM EST
aylin_sk87 reputationPosted Nov 23, 2004, 9:18 PM EST
eyes73 reputationPosted Nov 24, 2004, 12:16 AM EST
pchandekar3 reputationPosted Nov 24, 2004, 12:19 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 12:31 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 12:33 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 12:57 AM EST
eyes73 reputationPosted Nov 24, 2004, 2:19 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 2:33 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 2:47 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 2:59 AM EST
eyes73 reputationPosted Nov 24, 2004, 3:27 AM EST
aylin_sk87 reputationPosted Nov 24, 2004, 3:33 AM EST
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 23, 2008, 12:16 PM EST
http://www.c-sharpcorner.com/UploadFile/yougerthen/102162008174917PM/1.aspx
Ryan AlfordRank #1,411 · 1.2K reputationPosted Dec 24, 2008, 7:30 AM EST
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 24, 2008, 12:25 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts