tags:

views:

47

answers:

5

Whats the best way to take data from a datareader and manipulate that data, say taking a salary and dividing that salary by 12 then binding that data to a grid. I was thinking maybe a datareader to a dataset then looking through that to update the data, or is there a better way?

Need to do this at the application not the database so cant do the computation via the sql query.

+1  A: 

I am not sure where you are getting the data from. If it is a database why not try and do most of the obvious heavy lifting in the SQL Statement.

Example

SELECT annual_salary/12 AS month_salary FROM employees WHERE dept = 'Accounting'

Excuse my bad database normalization. Dept should be in a separate table and joined on.

uriDium
Please see the edit for the question. He want to do this at the application level and not at the database level.
rahul
A: 

Why not have the query that datareader is the result of just do the division for you?

AnthonyWJones
+2  A: 

Do you want to update the data to the dataset or read the data from the dataset and show the calculated result in the grid.

If latter is your need then you can write your calculation logic inside itemdatabound event of the datagrid and can bind the result to the corresponding cell.

rahul
A: 

If you are coming from SQL why not put the actual calculation inside the SQL?

If your business rules require you to keep logic out of the SQL then put it in the ItemDataBound event of a DataGrid (RowDataBound for GridView)...

Dining Philanderer
Thanks, guess this is probably the easiest way
A: 

Hi,

At my mind, you don't need a DataReader. You can choose a collection of typed object if you are using linq to sql for example. And update values inside, then bind it to a datagrid.

//an example

List result = yourProxy.GetObjects(); result.foreach(yto=> { (yto.Salary=yto.Salary/12) });

this.yourGrid.Datasource=result

Xstahef