Invoice.Select to return an array of data rows. I like that.
"Miha Markic" <miha at rthand com> wrote in message
news:OwkiYUFmHHA.4032@TK2MSFTNGP02.phx.gbl...
> You are changing the source within foreach, that's why you get odd
> behaviour.
> Instead, do a foreach loop over this.Invoice.Select(filter here).
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development
www.rthand.com > Blog:
http://cs.rthand.com/blogs/blog_with_righthand/ >
> "Jim Rand" <jimrand@ix.netcom.com> wrote in message
> news:ut%23uUu8lHHA.1776@TK2MSFTNGP05.phx.gbl...
>> Simple problem. If the company is null, replace it with last name and
>> first name:
>>
>> /* Replace null companies with last and first names */
>> DataView dv = new DataView((DataTable)this.Invoice, "Company = ''",
>> "InvoiceID", DataViewRowState.CurrentRows);
>> foreach (DataRowView drv in dv)
>> {
>> drv.Row["Company"] = drv.Row["LastName"] + ", " + drv["FirstName"];
>> }
>> this.AcceptChanges();
>>
>> Three rows were found in the DataView. While three replacements were
>> made, 1 row received two replacements and 1 row wasn't changed at all.
>> Is this a bug in ADO.NET or can you not change column values included in
>> the filter while iterating through the rows?
>>
>> The following code worked:
>>
>> /* Replace null companies with last and first names */
>> DataView dv = new DataView((DataTable)this.Invoice, "Company = ''",
>> "InvoiceID", DataViewRowState.CurrentRows);
>> if (dv.Count > 0)
>> {
>> List<int> list = new List<int>();
>> foreach (DataRowView drv in dv)
>> {
>> list.Add((int)drv.Row["InvoiceID"]);
>> }
>> for (int i = 0; i < list.Count; i++)
>> {
>> InvoiceRow row = this.Invoice.FindByInvoiceID(list[i]);
>> row.Company = row.LastName + ", " + row.FirstName;
>> }
>> }
>> this.AcceptChanges();
>>
>>
>