C# and slow update of System.Data.DataRow in ADO.NET
I'm using ADO.NET in a simple C# application.
There are two tables, TableA and TableB. TableA is a parent of Table B. TableA contains:
- id as a primary key (Int32)
- Other columns. I think it's irrelevant so I won't elaborate.
Table B has these columns:
- id (primary key) (Int32)
- tableAid (foreign key relationship with table A) (Int32 and primary key)
- X (double type)
- Y (double type)
I have created approximately 300 rows in table B. I want to update the columns values for X and Y to have the same value for each row. I'm currently doing this:
TableBRow[] rowsOfB = TableA.GetTableBRows();
for (int i = 0 ; i < rowsOfB.Length ; i++)
{
rowsOfB[i].X = newXvalue;
rowsOfB[i].Y = newYvalue;
}
This code seems to take a long time to run. My questions are (i) why is this slow ? and (ii) what is the recommended way of updating man开发者_如何学Pythony rows in a table? Is there a bulk update approach.
if you're doing a large update, generally creating a temp table, doing a bulk insert, join on this temp table and do your update is quicker than doing n updates.
精彩评论