Deleted Data Row and LINQ
Another interesting programming problem. I have the following code in VB.Net which throws error:
The error says "Deleted row information cannot be accessed through the row". Pretty clear message, so I did the following:
dataRow.Delete() 'One of the rows in dataSet dataSet.Tables("TableName").Rows.Cast(Of DataRow).FirstOrDefault(Function(dr) dr("ColumnName") = certainCondition)
dataSet.Tables("TableName").Rows.Cast(Of DataRow).FirstOrDefault(Function(dr) dr("ColumnName") = certainCondition AndAlso dr.RowState <> DataRowState.Deleted)
But the code above throws the same error. Apparently the deleted check has to be the first condition which again makes sense. Thus, the following code runs perfectly fine:
There you go.
dataSet.Tables("TableName").Rows.Cast(Of DataRow).FirstOrDefault(Function(dr) dr.RowState <> DataRowState.Deleted AndAlso dr("ColumnName") = certainCondition)
There you go.
Comments
Post a Comment