Fill table in dataset with query and then add columns?

  • Thread starter Thread starter Randall Parker
  • Start date Start date
R

Randall Parker

I'm filling up a dataset table with a database query. Then I'm binding the dataset to
an ASP.Net asp:DataGrid.

However, some derived columns have values that are too complicated to fill out in the
SELECT statement in the query. Can one add additional columns to a dataset after
initially creating a dataset with a database query?

What I want to do is to fill up the dataset with a query, create additional columns
(unless I can/should do that in the SELECT list?), loop thru the dataset and on each
row do some logic to decide how to fill out the derived columns.

The derived columns can all be text. I do not need to do updates on this table back
into the database. Is this a reasonable approach?
 
Yup. Just create a new DataColumn object, configure it and use the Add
method to append it to the Columns collection.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Randall,

Add a new DataColumn - see if you can get away with setting it's Expression
property to an appropriate calculated value, if not populate it using one of
the events on the DataTable. This table structure will then need to be setup
before you fill the data.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------
 
Yes, you can just use DataColumn name = new DataColumn("NameToUse",
typeof(TypeToUse);
//Set expression here if you see fit
DataSEtName.Tables[TableIndexes].Columns.Add(name);
 
Back
Top