I am Working with Vb.Net Project, through Web Service call method I get the result in DataTable's Object , now I need to add more columns after local calculations, I m doing all in loops and adding one by column's data through loop or modifying it, for a larger DataTable its too time taking. Is there any logic that I add those columns in one go rather traversing each DataRow?
Suppose I have a DataTable with 4 columns, (Name = dt) I need to add two more into it.
for 2000 rows I have to go for each row to initialize the value of newly added columns.
****Suppose I have calculations of new tentative columns into a Temp table. Is There any way so I can update the values of newly added columns (added into dt)by joins The tables (inside VB.NET code) on the bases of a common column (Primary Key Column)****
If the tempTbl is within the same DataSet as your primary Table (containing the Data), and you've got a 1:1 matching key relationship: yes, you can.
Add a DataRelation between your two tables within the DataSet and use it to retrieve a combined DataRow, containing the columns of all related tables.
Output:
The real magic is happening within the loop for the output. I'm accessing the desired value of the first child row, because due to the 1:1 DataRelation, I have made sure that each DataRow in Tbl1 has a pedant in Tbl2 that has the same SaleID.
So what I do is
DRow.GetChildRows("SaleIDRelation")(0)("Turnover")
:"SaleIDRelation"