Reputation:
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.
Upvotes: 0
Views: 111
Reputation: 2767
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)...
Upvotes: 0
Reputation: 654
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
Upvotes: 0
Reputation: 187070
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.
Upvotes: 2
Reputation: 189467
Why not have the query that datareader is the result of just do the division for you?
Upvotes: 0
Reputation: 13420
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.
Upvotes: 1