J
Jim Rand
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);
row.Company = row.LastName + ", " + row.FirstName;
}
}
this.AcceptChanges();
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);
row.Company = row.LastName + ", " + row.FirstName;
}
}
this.AcceptChanges();