Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个如下所示的数据表:
ID Name FKID1 FKID2 1 ABC -1 -1 2 ABD -1 -1 3 ABE -1 2 4 BCD 1 3
我如何使用 linq 替换数据表值,如下所示
ID Name FKID1 FKID2 1 ABC 2 ABD 3 ABE 2 4 BCD 1 3
试试这个
IEnumerable<DataRow> rows = from row in DataTableObj.AsEnumerable() select row; foreach (DataRow row in rows) { if(Convert.ToInt32(row["FKID1"])==-1) row["FKID1"] = DBNull.Value; if(Convert.ToInt32(row["FKID2"])==-1) row["FKID2"] = DBNull.Value; }