开发者

Problem updating multi-row

开发者 https://www.devze.com 2023-03-28 20:11 出处:网络
table:ProductComapny field:NameProduct NameProduct 1 1 1 4 5 i want update fields NameProduct where NameProduct= 1 to(NameProduct=1,NameProduct=2,NameProdu开发者_JAVA百科ct=3

table:ProductComapny

field:NameProduct

NameProduct

1

1

1

4

5

i want update fields NameProduct where NameProduct= 1 to(NameProduct=1,NameProduct=2,NameProdu开发者_JAVA百科ct=3

how can this work??

result

NameProduct

1

2

3

4

5


var source = new int[] {1,1,1,4,5};
var result = source.Select( (val,i) => val==1 ? i : val );


Try This:

using (DataClassesDataContext dc=new DataClassesDataContext())
    {
        var my = from a in dc.ProductComapny
                 where a.NameProduct== 1
                 select a;

        int i=1;
        foreach (var item in my)
        {
            item.NameProduct= i;
            dc.SubmitChanges();
            i++;
        }
    }
0

精彩评论

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