private void Form1_Load(object sender, EventArgs e) { ShopDB shopDB = new ShopDB(); var customersTableAdapter = new ShopDBTableAdapters.CustomersTableAdapter(); customersTableAdapter.Fill(shopDB.Customers); var ordersTableAdapter = new ShopDBTableAdapters.OrdersTableAdapter(); ordersTableAdapter.Fill(shopDB.Orders); var employeesTableAdapter = new ShopDBTableAdapters.EmployeesTableAdapter(); // employeesTableAdapter.Fill(shopDB.Employees); shopDB.Orders.Columns.Add("SurnameEmployee", typeof(String)); shopDB.Orders.Columns.Add("NameEmployee", typeof(String)); shopDB.Orders.Columns.Add("SurnameCustomer", typeof(String)); shopDB.Orders.Columns.Add("NameCustomer", typeof(String)); foreach (var orderRow in shopDB.Orders) { orderRow["NameEmployee"] = orderRow.EmployeesRow.FName; orderRow["SurnameEmployee"] = orderRow.EmployeesRow.LName; orderRow["SurnameCustomer"] = orderRow.CustomersRow.FName; orderRow["NameCustomer"] = orderRow.CustomersRow.LName; } dataGridView1.DataSource = shopDB.Orders; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].Visible = false; dataGridView1.Columns[3].Visible = false; dataGridView1.Columns["OrderDate"].Visible = false; }
private void Form1_Load(object sender, EventArgs e) { ShopDB shopDB = new ShopDB(); var employeesTableAdapter = new ShopDBTableAdapters.EmployeesTableAdapter(); employeesTableAdapter.Fill(shopDB.Employees); var ordersTableAdapter = new ShopDBTableAdapters.OrdersTableAdapter(); ordersTableAdapter.Fill(shopDB.Orders); ShopDB.EmployeesDataTable employees = employeesTableAdapter.GetData(); ShopDB.OrdersDataTable orders = ordersTableAdapter.GetData(); employees.Columns.Add("Count", typeof(int)); foreach (DataRow employeeRow in employees.Rows) { employeeRow["Count"] = orders.Count(o => o.EmployeeID == (int)employeeRow["EmployeeID"]); } dataGridView1.DataSource = employees; this.dataGridView1.Columns["FName"].Visible = false; this.dataGridView1.Columns["LName"].Visible = false; this.dataGridView1.Columns["MName"].Visible = false; this.dataGridView1.Columns["Salary"].Visible = false; this.dataGridView1.Columns["PriorSalary"].Visible = false; this.dataGridView1.Columns["HireDate"].Visible = false; this.dataGridView1.Columns["TerminationDate"].Visible = false; this.dataGridView1.Columns["ManagerEmpID"].Visible = false; //// }
static void Main(string[] args) { ShopDB shopDB = new ShopDB(); var employeesTableAdapter = new ShopDBTableAdapters.EmployeesTableAdapter(); employeesTableAdapter.Fill(shopDB.Employees); var ordersTableAdapter = new ShopDBTableAdapters.OrdersTableAdapter(); ordersTableAdapter.Fill(shopDB.Orders); var orderDetailsTableAdapter = new ShopDBTableAdapters.OrderDetailsTableAdapter(); orderDetailsTableAdapter.Fill(shopDB.OrderDetails); ShopDB.EmployeesDataTable employees = employeesTableAdapter.GetData(); ShopDB.OrdersDataTable orders = ordersTableAdapter.GetData(); employees.Columns.Add("Count", typeof(int)); foreach (DataRow employeeRow in employees.Rows) { employeeRow["Count"] = orders.Count(o => o.EmployeeID == (int)employeeRow["EmployeeID"]); foreach (DataColumn column in employees.Columns) { if (column.ColumnName == "EmployeeID" || column.ColumnName == "Count") { Console.WriteLine("{0}: {1}", column.ColumnName, employeeRow[column]); } } Console.WriteLine(); } }