adding columns to an already-filled datatable?

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top