DataTable предназначен для хранения данных, а не для операций над ними, вся логика строится уже на втором или третьем слое (пример показан выше). Все что можно сделать это вычислить колонку:public static DataTable GetOrders() {
DataTable orders = new DataTable();
orders.Columns.Add(new DataColumn("ID", typeof(int)));
orders.Columns.Add(new DataColumn("Quantity", typeof(int)));
orders.Columns.Add(new DataColumn("Price", typeof(decimal)));
orders.Columns.Add("Total", typeof(decimal), "Quantity * Price");
DataRow row;for (int i = 0; i < 10; i++)
{ row = orders.NewRow();
row["ID"] = i + 1;
row["Price"] = i + 1.9;
row["Quantity"] = i + 4;
orders.Rows.Add(row);}
return orders;}
или строку:
public static DataTable GetOrders()
{ DataTable orders = new DataTable();
orders.Columns.Add(new DataColumn("ID", typeof(int)));
orders.Columns.Add(new DataColumn("Quantity", typeof(decimal)));
orders.Columns.Add(new DataColumn("Price", typeof(decimal)));
orders.Rows.Add(0, 2, 4.7);
orders.Rows.Add(1, 4, 12.8);
orders.Rows.Add(2, 1, 2.6);
orders.Rows.Add(3, 1, 2.5);
int _count = (int)orders.Compute("COUNT(ID)", "");
decimal _sum = (decimal)orders.Compute("SUM(Quantity)", "");
decimal _avg = (decimal)orders.Compute("AVG(Price)", "");
orders.Rows.Add(_count, _sum, _avg);
return orders;}
Это хоть в пределах видимости void mainprog()?
Данное сообщение получено с сайта GotDotNet.RU
Последний раз редактировалось 12 May 2008 03:59
|