Performing column value changes when filling a dataset

  • Thread starter Thread starter Shannon Broskie
  • Start date Start date
S

Shannon Broskie

Hello,

Let me first say that I'm pretty new to ADO.NET.

I have an application where extra data needs to be added to additional
columns in a dataset that do not come from a database.

Example:
I pull back security(stock / bond) info and populate that in a dataset. For
every record that comes back, I need to add an additional column named
accrued interest. The complexity of this calculation does not allow for it
to be calculated in SQL at the server.

Is there a way to:

1) Add the additional columns to the dataset before the dataset is filled?
2) Perhaps an event off the fill method that would allow additional
processing on each record as it comes in?

If not, is the best way to:
1) Create an in-memory dataset and set up the columns (perhaps
strongly-typed).
2) Use a SQLDataReader to pull back the data and write code to transfer each
column over the to in-memory dataset along with the extended processing for
additional columns.

In the current incarnation of the application (written in Delphi), I have to
create an in-memory ADO recordset and set up all of the columns. I then
pull back the data with another recordset and transfer all data to the
recordset with the extra columns.

Thanks for your help.
 
You can modify the structure of a DataTable object by altering the Columns
collection. After you populate the DataTable you can add a new DataColumn
to the DataTable then iterate through the Rows collection of the DataTable
and set the newly added column's value accordingly.

References:
DataTable.Columns Collection:
http://msdn.microsoft.com/library/d...frlrfsystemdatadatatableclasscolumnstopic.asp
DataColumnCollection Members:
http://msdn.microsoft.com/library/d...fsystemdatadatacolumncollectionclasstopic.asp
DataColumn Class:
http://msdn.microsoft.com/library/d.../html/frlrfsystemdatadatacolumnclasstopic.asp
 
Back
Top