Which is recommended
while (reader.Read())
{
table.Rows.Add(
new object[] { reader[0], reader[1], reader[2], reader[3] }
);
table.AcceptChanges();
}
or
while (reader.Read())
{
table.Rows.Add(
new object[] { reader[0], reader[1], reader[2], reader[3] }
);
}
table.AcceptChanges();
Note where the table.AcceptChanges is placed.
EDIT 1
Here is the code block:
protected void Page_Load(object sender, EventArgs e)
{
IDataReader reader = cust.GetCustomerOrderSummary("99999");
using (DataSet ds = new DataSet())
{
using (DataTable table =
new DataTable { TableName = "OrderSummary" })
{
DataColumn idColumn = table.Columns.Add("number", typeof(int));
table.Columns.Add("name", typeof(string));
table.Columns.Add("quantity", typeof(int));
table.Columns.Add("prev_quantity", typeof(int));
table.PrimaryKey = new DataColumn[] { idColumn };
while (reader.Read())
{
table.Rows.Add(
new object[]{ reader[0], reader[1], reader[2], reader[3] }
);
table.AcceptChanges();
}
ds.Tables.Add(table);
rptCustomerOrder report =
new rptCustomerOrder { DataSource = ds };
ReportViewer1.Report = report;
}
}
}
EDIT 2
After reading the MSDN article here I decided to place the AcceptChanges() outside the loop based on the following statement (from the article):
Calling AcceptChanges at the DataTable level causes the AcceptChanges method for each DataRow to be called.