开发者

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:

  1. id as a primary key (Int32)
  2. Other columns. I think it's irrelevant so I won't elaborate.

Table B has these columns:

  1. id (primary key) (Int32)
  2. tableAid (foreign key relationship with table A) (Int32 and primary key)
  3. X (double type)
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜