/// <summary> /// Update the textbox contain information about all cars in inventory /// </summary> public void UpdateOutput() { // load and fill the inventory table var inventoryTable = new AutoLotDataSet.InventoryDataTable(); InventoryTableAdapter adapter = new InventoryTableAdapter(); adapter.Fill(inventoryTable); // for each record, show the car information // note use of Environment.NewLine as AppendText() needs more than \n textBoxOutput.AppendText($"Inventory{Environment.NewLine}"); foreach (var row in inventoryTable) { textBoxOutput.AppendText($"{row.CarId} {row.Make} {row.Color} {row.Name}{Environment.NewLine}"); } textBoxOutput.AppendText($"Count = {inventoryTable.Count}{Environment.NewLine}"); // now show a linq query where CarId < 5 var query = from row in inventoryTable.AsEnumerable() where row.CarId < 5 select row; // just another version using linq methods and lambda var query2 = inventoryTable.AsEnumerable().Where(row => row.CarId < 5); textBoxOutput.AppendText($"{Environment.NewLine}LINQ result CarId < 5{Environment.NewLine}"); foreach (var row in query) { textBoxOutput.AppendText($"{row.CarId} {row.Make} {row.Color} {row.Name}{Environment.NewLine}"); } }
private static void BuildDataTableFromQuery(AutoLotDataSet.InventoryDataTable data) { var cars = from car in data.AsEnumerable() where car.Field <int>("CarId") > 5 select car; DataTable newTable = cars.CopyToDataTable(); // Использование этого результирующего набора для создания нового DataTable for (int currentRow = 0; currentRow < newTable.Rows.Count; currentRow++) { for (int currentColumn = 0; currentColumn < newTable.Columns.Count; currentColumn++) { Console.Write(newTable.Rows[currentRow][currentColumn].ToString().Trim() + "\t"); } } Console.WriteLine(); }