adding columns to an already-filled datatable?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

In my Win app, I call a method that returns a datatable with all its columns
and is filled with data. After the table's returned, I need to add another
column to the datatable that will include data from an ascii file. For
example, the table may contain two columns: "emplcode" and "HrsWorked". Once
I receive this table with all the data, I need to add another column to the
datatable ("Name"), go through every row in the datatable and find the
"emplcode" in the ascii file. Once I've found it, I'll copy the data, in the
file, to the datacolumn.

Is that possible?
 
VMI,

Yes, it absolutely should be. All you have to do is create a new
DataColumn and add it to the DataTable in question using the Add method on
the DataColumnCollection returned by the Columns property.

Then, you can cycle through the columns normally, and then add the data.
You might want to call AcceptChanges when you are done, depending on whether
or not you want the edits to be visible (when you set the column values,
each row will have an edit associated with it).

Hope this helps.
 
Back
Top