无法删除多行具有相同列值的数据库记录?

时间:2013-12-31 12:33:56

标签: .net c#-4.0 linq-to-sql

我有一个表格,其中我有多个行具有相同的列名,如下所示

ID   Column1   Column2   Column3

1     test     value1    katy

2     test     value2    kavita

3     test     value3    henry

4     test     value4    stalin

我使用以下技术检索记录并尝试删除它们,但它说出了强制转换错误,

TableName DeleteSession = (TableName)from s in Data.TableName where s.Column1 == "test"  select s;

Data.TabelName.DeleteOnSubmit(DeleteSession);
Data.SubmitChanges();

如何删除具有相同列名称的行

1 个答案:

答案 0 :(得分:0)

试试这个

var DeleteSession = (from s in Data.TableName 
                     where s.Column1 == "test"  
                     select s).ToList();

Data.TabelName.DeleteAllOnSubmit(DeleteSession);
Data.SubmitChanges();

新记录

var NewSession = (from s in Data.TableName
                  where s.Column1 == "test"
                  select new Table2Name { Column1 = s.Column1...etc }).ToList

Data.Table2Name.InsertAllOnSubmit(NewSession);
Data.SubmitChanges();